2Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their actions without sharing the same address space. We discuss in this section the various message passing techniques and issues related to them.
3Message Passing System The function of a message system is to allow processes to communicate without the need to resort to the shared data.Messages sent by a process may be of either fixed or variable size.If processes P and Q want to communicate, a communication link must exist between them and they must send messages to and receive messages from each other through this link.
4IPC If P and Q wish to communicate, they need to: Establish a connection link between themExchange messages via send/receive
5IPC Implementation of communication link Physical (e.g. shared memory, hardware bus)Logical (e.g. logical properties)
6Implementation Questions How are links established?Can a link is associated with more than two processes?How many links can there be between every pair of communicating processes?
7Implementation Questions What is the capacity of a link?Is the size of a message that the link can accommodate fixed or variable?Is a link Unidirectional or bi-directional?
8IPCHere are several methods for logically implementing a link and the send and receive options:Direct or indirect communicationSymmetric or asymmetric communicationAutomatic or explicit bufferingSend by copy or send by referenceFixed size or variable size messages
9We now look at the different types of message systems used for IPC.
10Direct CommunicationWith direct communication, each process that wants to communicate must explicitly name the recipient or sender of the communication. The send and receive primitives are defined as:Send(P, message) – send a message to process PReceive(Q, message) – receive a message from process Q.
11Direct CommunicationA communication link in this scheme has the following properties:A link is established automatically between every pair of processes that want to communicate. The processes need to know only each other’s identity to communicateA link is associated with exactly two processes.Exactly one link exists between each pair of processes.
12Direct CommunicationUnlike this symmetric addressing scheme, a variant of this scheme employs asymmetric addressing, in which the recipient is not required to name the sender.Send(P, message) – send a message to process PReceive(id, message) – receive a message from any process; the variable id is set to the name of the process with which communication has taken place
13Indirect communication Messages are directed and received from mailboxes (also referred to as ports).Each mailbox has a unique id.Processes can communicate only if they share a mailbox.
14Indirect communication Operations:Create a new mailboxSend and receive messages through mailboxDestroy a mailbox
15Indirect communication Mailbox sharingP1, P2 and P3 share mailbox A.P1 sends; P2 and P3 receive.Who gets the message?
16Indirect Communication Allow a link to be associated with at most two processes.Allow only one process at a time to execute a receive operation.Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.
17Indirect Communication With indirect communication, messages can be sent to and received from mailboxes. Here, two processes can communicate only if they share a mailbox. The send and receive primitives are defined as:Send(A, message) – send a message to mailbox A.Receive(A, message) – receive a message from mailbox A.
18Indirect Communication A communication link in this scheme has the following properties:A link is established between a pair of processes only if both members have a shared mailbox.A link is associated with more than two processes.A number of different links may exist between each pair of communicating processes, with each link corresponding to one mailbox.
19SynchronizationCommunication between processes takes place by calls to send and receive primitives (i.e., functions). Message passing may be either blocking or non-blocking also called as synchronous and asynchronous.Blocking send: The sending process is blocked until the receiving process or the mailbox receives the message.Non-blocking send: The sending process sends the message and resumes operation.Blocking receive: The receiver blocks until a message is available.Non-blocking receiver: The receiver receives either a valid message or a null.
20BufferingWhether the communication is direct or indirect, messages exchanged by the processes reside in a temporary queue. This queue can be implemented in three ways:Zero Capacity: The queue has maximum length zero, thus the link cannot have any messages waiting in it. In this case the sender must block until the message has been received.Bounded Capacity: This queue has finite length n; thus at most n messages can reside in it. If the queue is not full when a new message is sent, the later is placed in the queue and the sender resumes operation. If the queue is full, the sender blocks until space is available.
21BufferingUnbounded Capacity: The queue has infinite length; thus the sender never blocks.
22UNIX/Linux IPC ToolsUNIX and Linux operating systems provide many tools for interprocess communication, mostly in the form of APIs but some also for use at the command line. Here are some of the commonly supported IPC tools in the two operating systems.PipeNamed pipe (FIFO)BSD Socket (Barkley Software Distribution) Uni of CaliforniaTLIMessage queueShared memoryEtc.
23Unix/Linux pipe Important system calls pipe, read, write, close Pipe: create a pipe for IPCRead: read from a pipeWrite: write to a pipeClose: close or destroy a pipe