Advantages of Message Passing in IPC (Inter-Process Communication)
1. Processes can exist on different computers:
Message passing allows processes to communicate even if they are running on separate
machines.
2. No need to estimate shared memory size:
The process does not need to guess or manage the size of the shared memory area required for
communication.
3. Simplified communication setup:
The process does not have to define a complex structure for communication. This simplifies
development.
4. Buffered message delivery:
The message stays in the system buffer until it is delivered. However, during this period, someone
could potentially tamper with it.
5. System protection against overflow:
If the data area is smaller than the message size, the operating system generates a warning to
prevent overflow.
---
IPC Basics
* IPC (Inter-Process Communication) is best achieved using message passing systems.
* Communication between user processes happens by sending and receiving messages.
IPC provides two main operations:
* send(message)
* receive(message)
There are two methods to implement IPC:
* Shared Memory
* Message Passing
---
Communication Link in IPC
When two processes want to communicate:
* They send and receive messages.
* This setup is known as a communication link between the processes.
Communication links can be implemented in the following ways:
1. Direct or Indirect Communication
2. Synchronous or Asynchronous Communication
3. Automatic or Explicit Buffering
4. Send by Copy or Send by Reference
5. Fixed-size or Variable-size Messages
---
Direct Communication
* In this type, the sender must explicitly name the receiver and vice versa.
* The send and receive primitives are defined as:
send(P, message) // Sends a message to process P
receive(Q, message) // Receives a message from process Q
---
Properties and Disadvantages of Direct Communication
Properties:
* Processes must identify each other explicitly.
* One communication link exists between each pair of processes.
* The link is automatically established between each pair.
Disadvantage:
* If the name of any process is changed, all references to that name in every related process must
be updated. This makes maintenance difficult.
---
Indirect Communication
* Messages are sent to and received from mailboxes.
* A mailbox is a system object where messages are stored and accessed.
Properties of mailboxes:
* Messages are placed in and removed from mailboxes by processes.
* Each mailbox has a unique identity.
Message operations:
send(mailbox, message)
receive(mailbox, message)
---
Mailbox-Based Communication Properties
1. A link is established only if both processes share the same mailbox.
2. One link can be associated with two or more processes.
3. Different communicating pairs can use different mailboxes, each corresponding to a unique link.
---
Synchronous Communication
* A synchronous operation blocks the process until the communication is completed.
* Example:
If the sender executes a send call, it waits (gets blocked) until the receiver executes a receive call
and the message is delivered.
Advantage:
* Guaranteed delivery of messages.