Operating System - Inter-Process Communication – Message Passing System
In a multiprogramming operating system, multiple processes run concurrently. These processes often need to communicate with each other — for coordination, data sharing, or synchronization.
One of the most common methods of IPC is the Message Passing System.
What is Message Passing in IPC?
Message Passing is a method where processes communicate by sending and receiving messages. Unlike shared memory, they do not share memory space — instead, all data is exchanged explicitly via messages.
Basic Concepts:
Term | Description |
---|---|
Sending | A process sends a message to another process. |
Receiving | A process receives a message sent by another process. |
Message | A data unit that may include a sender ID, receiver ID, message content, etc. |
Communication Link | A logical or physical path for message transfer. |
Types of Message Passing:
Type | Explanation |
---|---|
Direct Communication | Processes must name each other explicitly (e.g., send(P2, message) ). |
Indirect Communication | Messages go through mailboxes (message queues) — no need to name the other process. |
Synchronous (Blocking) | Sender waits until the receiver gets the message (tight coordination). |
Asynchronous (Non-blocking) | Sender continues execution immediately after sending the message. |
Diagram: Message Passing Between Two Processes
+------------+ Message +------------+
| Process A | -----------------> | Process B |
| (Sender) | (send msg) | (Receiver) |
+------------+ +------------+
In case of bidirectional communication:
+------------+ Message 1 +------------+
| Process A | -----------------> | Process B |
| | <----------------- | |
+------------+ Message 2 +------------+
Ex:2
Imagine two friends texting:
-
Friend A sends a message: “Meet at 5.”
-
Friend B receives it and replies: “Okay!”
This is asynchronous message passing — no shared memory, just passing data via messages.
Advantages:
-
No need for shared memory (good for distributed systems).
-
Safer communication (less risk of memory corruption).
Disadvantages:
-
Slower than shared memory for large data.
-
More overhead in context switching and kernel involvement.