written 2.7 years ago by |
In Co-operative processes, inter process communication(IPC) is an important mechanism for processes to communicate between each other and achieve proper synchronization between them. Processes can interact with each other via:
1) Shared Memory: In this method, processes must share some common variable(s). The processes then process these variables and store the result in a common block of memory known as "Shared Memory". The processes use the values of these shared variables to perform their required tasks. Examples of this type of communication is the Producer-Consumer problem, Readers-Writers problem, etc.
2) Message-Passing Method: In this method processes communicate via a communication link or using send() and receive() methods. A standard message has two parts: header and body.
The header part is used to store the type of message, destination ID, length of the message, source ID, and control information. The control information contains information about what to do if runs out of buffer space, sequence number and priority. Message is stored in a queue and sent using the First In First Out method.
Message Passing through Communication Link:
Direct and Indirect Communication Link:
Direct Communication links are implemented when the processes use a specific process identifier for the communication, but it is hard to identify the sender ahead of time. For example the print server.
Indirect Communication is done via a shared mailbox (port), which consists of a queue of messages. The sender keeps the message in mailbox and the receiver picks them up.
Message Passing through Exchanging the Messages:
Synchronous and Asynchronous Message Passing:
In Direct message passing, The process which wants to communicate must explicitly name the recipient or sender of the communication. e.g. send(p1, message) means send the message to p1. Similarly, receive(p2, message) means to receive the message from p2.
Here, the communication link gets established automatically (unidirectional/ bidirectional). In this, one pair of sender and receiver should have only one pair of links. The receiver doesn't necessarily need a link to receive a message from the sender as long the sender and receiver have a link between them. The process names must be changed with caution in this case otherwise the links might break between the processes.
In Indirect message passing, processes use mailboxes (aka ports) for sending and receiving messages. Each mailbox has a unique ID and processes can communicate only if they share a mailbox. Links are established only if processes share a common mailbox and a single link can be associated with many processes. Each pair of processes can share several communication links and these links may be unidirectional or bi-directional.
The standard primitive used for sending a message to mailbox A: send(A, message)
The primitive for the receiving the message from mailbox A: receive(A, message)