ipc (interprocess communication). interprocess communication (ipc) ipc provides a mechanism to allow...

23
Lecture 8 IPC (Interprocess Communication)

Upload: johnny-grater

Post on 01-Apr-2015

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Lecture 8IPC (Interprocess Communication)

Page 2: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Interprocess 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.

Page 3: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Message Passing SystemThe 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.

Page 4: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

IPCIf P and Q wish to communicate, they need

to:

Establish a connection link between themExchange messages via send/receive

Page 5: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

IPCImplementation of communication link

Physical (e.g. shared memory, hardware bus)Logical (e.g. logical properties)

Page 6: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Implementation QuestionsHow 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?

Page 7: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Implementation QuestionsWhat 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?

Page 8: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

IPCHere are several methods for logically implementing a

link and the send and receive options: Direct or indirect communication Symmetric or asymmetric communication Automatic or explicit buffering Send by copy or send by reference Fixed size or variable size messages

Page 9: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

We now look at the different types of message systems used for IPC.

Page 10: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Direct 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.

Page 11: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Direct 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 communicate

A link is associated with exactly two processes. Exactly one link exists between each pair of

processes.

Page 12: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Direct 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 P Receive(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

Page 13: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Indirect communicationMessages 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.

Page 14: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Indirect communicationOperations:Create a new mailboxSend and receive messages through mailboxDestroy a mailbox

Page 15: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Indirect communicationMailbox sharing

P1, P2 and P3 share mailbox A.P1 sends; P2 and P3 receive.Who gets the message?

Page 16: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Indirect CommunicationAllow 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.

Page 17: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Indirect CommunicationWith 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.

Page 18: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Indirect CommunicationA 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.

Page 19: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

SynchronizationCommunication 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.

Page 20: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

BufferingWhether 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.

Page 21: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

BufferingUnbounded Capacity: The queue has infinite

length; thus the sender never blocks.

Page 22: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

UNIX/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.

Pipe Named pipe (FIFO) BSD Socket (Barkley Software Distribution) Uni of California TLI Message queue Shared memory Etc.

Page 23: IPC (Interprocess Communication). Interprocess Communication (IPC) IPC provides a mechanism to allow processes to communicate and to synchronize their

Unix/Linux pipeImportant 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