Skip to content
Sahithyan's S3
1
Sahithyan's S3 — Operating Systems

Inter-process Communication

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.

A region of memory is shared between processes. Processes manage the data sharing mechanism.

Synchronization is required to avoid race conditions in this model.

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.

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

Processes refer to each other in the syscalls. Link established automatically. Only 1 link per pair of processes.

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.

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.

Aka. anonymous pipes. Created using pipe() syscall. Unidirectional. Requires parent-child relationship. Used for simple producer-consumer scenarios.

Has a name in the filesystem. Bidirectional. No parent–child requirement. Multiple processes can use them.