Inter-Process Communication¶
IPC Overview¶
Inter-process communication (IPC) refers to OS-supported mechanisms that allow multiple processes to synchronize, coordinate, and communicate.
Two broad categories:
Message-based IPC: sockets, pipes, message queues
Memory-based IPC: shared memory, memory-mapped files
Other higher-level IPC mechanisms include Remote Procedure Calls (RPC) and synchronization primitives (mutexes, semaphores).
Message-Based IPC¶
Processes create messages and send/receive them through OS-managed channels (buffers, FIFO queues).
OS kernel establishes the channel and performs every IPC operation
Both send and receive require a system call + data copy
A simple request-response = 4 user/kernel crossings + 4 data copies
Drawback: overhead of kernel crossings and data copies
Benefit: simplicity — kernel handles channel management and synchronization
Forms of Message Passing¶
Pipes:
Two endpoints only; no message structure — just a byte stream
Commonly connect stdout of one process to stdin of another
Part of POSIX standard
Message Queues:
Understand message structure; support priorities and scheduling
APIs: POSIX and System V
Sockets:
The port abstraction serves as the message-passing endpoint
send()/recv()move data in/out of kernel socket bufferSocket creation associates kernel-level protocol processing (e.g., TCP/IP stack)
Work for both inter-machine and intra-machine communication
OS optimizes local communication by bypassing full protocol stack
IPC Command Line Tools¶
ipcs— list all IPC facilities (-mfor shared memory only)ipcrm -m <shmid>— remove a shared memory segment