Aka. IPC. Processes may be:
- Independent (no shared state)
- Cooperating (share data or communicate)
When processes cooperate, they need a way to communicate and synchronize. This is done using IPC mechanisms.
2 major IPC models.
Shared Memory
Section titled “Shared Memory”A region of memory is shared between processes. Processes manage the data sharing mechanism.
Synchronization is required to avoid race conditions in this model.
Message Passing
Section titled “Message Passing”kernel handles a message queue. Processes send and receive messages using syscalls. A communication link must be established between 2 processes.
Useful for distributed systems.
Communication Link
Section titled “Communication Link”Characteristics of a communication link:
- Buffering capacity
Maximum number of messages that can be in transit. Can be one of: Zero, bounded, unbounded. - Direction
Whether the communication is one-way (unidirectional) or two-way (bidirectional). - Synchronization
Wehther blocking or non-blocking. - Direct or indirect
Direct
Section titled “Direct”Processes refer to each other in the syscalls. Link established automatically. Only 1 link per pair of processes.
Indirect
Section titled “Indirect”Aka. mailbox/port based. Processes use shared mailboxes, which may be shared with many processes. The shared mailbox must be set up before communication. Multiple links possible within a pair of processes. OS resolves conflicts when they occur. Not secure as all processes sharing a mailbox can intercept the messages.
Buffering
Section titled “Buffering”Queue of messages is maintained by the OS.
Capacity of the queue can be:
- Zero: No messages can be queued. Sender and receiver must be ready at the same time.
- Bounded: Queue has a fixed size. Sender waits if full. Receiver waits if empty.
- Unbounded: Queue has no size limit. Sender never waits. Receiver waits if empty.
A unidirectional communication channel used for sending a stream of bytes from one process to another. A kernel-managed buffer. A byte stream (similar to a file) and not message-based.
Has 2 endpoints:
- write end
- read end
Data written is stored in the pipe’s buffer until another process reads it. read end is blocked if buffer is empty. write end is blocked if buffer is full (unless non-blocking). Pipe exists as long as file descriptors are open.
The pipe operator (|) in shells connects the stdout of one process to the stdin of another using a pipe.
Ordinary Pipes
Section titled “Ordinary Pipes”Aka. anonymous pipes. Created using pipe() syscall. Unidirectional. Requires parent-child relationship. Used for simple producer-consumer scenarios.
Named Pipes
Section titled “Named Pipes”Has a name in the filesystem. Bidirectional. No parent–child requirement. Multiple processes can use them.