CSCE 313 Lecture 15

From Notes
Jump to navigation Jump to search

« previous | Thursday, March 8, 2011 | next »

Inter-Process Communication (IPC)

Processes in system can be independent or cooperating. Cooperating processes can be affected (modifying shared data).

Fundamental communication models:

  1. Process A and Process B have shared memory between them.
  2. Each process has its own memory space ("mailbox"), and they access each other's memory through the kernel

Message Passing

sending and receiving

In order for processes to communicate, they need to establish a link

Link Implementations:

  • Physical shared hardware (memory or bus)
  • logical properties

Direct Communication involves specifying the process to send to or receive from:

  • send message to process P
  • receive message from process Q

Indirect communication relies on mailboxes (ports), each of which has a unique ID.

  • A link is established only if processes share a common mailbox
  • Therefore a link can be associated with multiple processes
  • Who gets the message if multiple processes linked?

Synchronization

Blocking vs. Non-blocking message

POSIX IPC

These commands are available in sys/msg.h

primitive POSIX Function Description
message queues msgget(key_t key, int msgflg); create or access
msgctl control
msgsnd/msgrcv send/receive message
semaphores semget create or access
semctl control
semop wait or post operation
shared memory shmget create or access
shmctl control
shmat/shmdt attach to / detach from process

IPC status can be observed using ipcs command from prompt:

IPC status from <running system> as of Thu Mar  8 10:39:58 CST 2012
T     ID     KEY        MODE       OWNER    GROUP
Message Queues:

T     ID     KEY        MODE       OWNER    GROUP
Shared Memory:

T     ID     KEY        MODE       OWNER    GROUP
Semaphores:

Naming xxGET

Condition variables and mutex locks
based on a memory variable and does not work across processes
Pipes
Uses file descriptors
Works across processes, but not for unrelated process (relies on inherited file descriptors)
Named Pipes
Uses file system as name space for pipe
Works across any processes
file system (disk) overhead
IPC Objects
system-wide integer keys