Interprocess Communication (IPC)
Processes within a system may be Independent or Cooperating.
Cooperating process can affect or be affected by other processes, including sharing data
Cooperating processes need interprocess communication (IPC)
Two models of IPC:
- Shared memory
- Message passing
Shared Memory
Shared Memory is the memory that may be simultaneously (同时) accessed by multiple programs with an intent to provide communication among them or avoid redundant copies.
Two or more process can access the common memory.
Synchronous and Asynchronous Message Passing:
Blocking is considered synchronous
◦ Blocking send has the sender block until the message is received
◦ Blocking receive has the receiver block until a message is available
Non-blocking is considered asynchronous
◦ Non-blocking send has the sender send the message and continue
◦ Non-blocking receive has the receiver receive a valid message or null
There are basically three most preferred combinations:
- Blocking send and blocking receive
- Non-blocking send and Non-blocking receive
- Non-blocking send and Blocking receive (Mostly used)
Direct message passing
Definition: The process which want to communicate must explicitly name the recipient or sender of communication.
The communication link get established automatically, which can be either unidirectional or bidirectional
But one link can be used between one pair of the sender and receiver and one pair of sender and receiver should not possess more than one pair of link.
Disadvantage: If the name of one process changes, this method will not work.
Indirect message passing
Definition: Processes uses mailboxes (also referred to as ports) for sending and receiving messages.
A single link can be associated with many processes.
Each pair of processes can share several communication links and these link may be unidirectional or bi-directional.
The required operations are:
- create a mail box,
- use this mail box for sending and receiving messages,
- destroy the mail box.
Disadvantage: More than two processes sharing the same mailbox and one of the process sends a message to the mailbox, which process will be the receiver?
Solution:
- forcing that only two processes can share a single mailbox
- enforcing that only one process is allowed to execute the receive at a given time
- select any process randomly and notify the sender about the receiver.
How are links established?
Direct communication: name process to communicate
Indirect communication: name mailbox (port) to communicate, which consists of queue of messages. Sender keeps the message in mailbox and receiver picks them up.
Implementation of communication link:
physical (e.g., shared memory, hardware bus)
logical (e.g., logical properties)
Can a link be associated with more than two processes?
In Direct message passing, a link can be only used between one pair of the sender and receiver. (NO)
In Indirect message passing, a link can be associated with many processes.(YES)
How many links can there be between every pair of communicating processes?
In Direct message passing, one pair of sender and receiver can only have one pair of link.
In Indirect message passing, one pair of processes can share several communication links.
What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable?
A link has some capacity that determines the number of messages that can reside in it.
-
zero capacity
In zero capacity, sender wait until receiver inform sender that it has received the message. -
bounded capacity
-
unbounded capacity
In non-zero capacity cases, a process does not know whether a message has been received or not after the send operation.
The message size can be of fixed size or of variable size.
Fixed size is easy for OS designer but complicated for programmer
Variable size is easy for programmer but complicated for the OS designer
-
A standard message can have two parts: header and body.
The header part is used for storing Message type, destination id, source id, message length and control information. -
Generally, message is sent using FIFO style.
Is a link unidirectional or bi-directional?
Both Direct message passing and In Indirect message passing can be either unidirectional or bidirectional.
Reference
https://www.geeksforgeeks.org/inter-process-communication-ipc/