Inter-process communication

Also known as: IPC

On this page 8

Inter-process communication (IPC) is the set of mechanisms an operating system provides so that separate processes can exchange data and synchronize their actions despite running in isolated address spaces. Among the OS fundamentals, IPC is the deliberate, kernel-controlled exception to process isolation: every process normally sees only its own virtual memory, so any cooperation between programs must pass through channels that the kernel creates, names, protects and tears down.

In modern operating systems, IPC underpins almost everything a user sees. A shell pipeline, a browser that renders each tab in its own sandboxed process and a database client talking to a local server all depend on it. Choosing the right IPC primitive is a trade-off between speed, safety, structure and portability.

How inter-process communication crosses the isolation boundary

IPC works because the kernel mediates every exchange between address spaces. A process cannot read another process’s memory directly; instead it issues a system call such as write(), sendmsg() or mmap(), and the kernel either copies the data into a buffer it owns or maps the same physical pages into both processes. Each channel is represented by a kernel object with a handle, usually a file descriptor on Unix-like systems or a handle on Windows, so normal access control applies.

Two fundamental models exist. In message passing, the kernel copies data from sender to receiver, which costs at least two copies and a system call per message but keeps the processes cleanly separated. In shared memory, the kernel sets up the mapping once and afterwards the processes communicate at memory speed with no kernel involvement, at the price of needing explicit synchronization to avoid race conditions.

The table below shows the kernel role in each phase.

PhaseWhat the kernel doesTypical cost
SetupCreates the object, assigns a name or handle, checks permissionsOne or more system calls
TransferCopies data or maps shared pagesCopy per message, or none after mapping
SynchronizationBlocks and wakes waiting processesA context switch when a process sleeps
TeardownReleases buffers when the last handle closesReference count update
Kernel role in an IPC exchange

Main IPC mechanisms and their properties

Operating systems offer a family of IPC primitives, each tuned to a different pattern of cooperation. The POSIX standard defines a portable core, while Windows provides parallel objects with different names and semantics.

MechanismData modelScopeTypical use
Anonymous pipeUnidirectional byte streamRelated processes on one hostShell pipelines such as ls | grep
Named pipe (FIFO)Byte stream with a file system nameUnrelated processes on one hostSimple local services, Windows named pipes
Unix domain socketStream or datagram, can pass descriptorsOne hostLocal daemons, display servers, databases
Message queueDiscrete prioritized messagesOne hostDecoupled producers and consumers
Shared memoryCommon memory regionOne hostLarge buffers, audio and video frames
SignalSmall numbered notificationOne hostTermination, reload, child exit
Network socketStream or datagram over TCP or UDPLocal or remote hostsClient-server and distributed systems
Common IPC mechanisms compared

Signals deserve a caveat: they carry almost no data and interrupt the receiver asynchronously, so they are suitable for notifications rather than data transfer. Unix domain sockets are often the most versatile local choice because they support credentials checks and can pass open file descriptors between processes, a capability that privilege-separated services rely on.

Synchronization as part of IPC

Exchanging data is only half of IPC; the other half is coordinating when processes act. Pipes and sockets synchronize implicitly, because a reader blocks until data arrives and a writer blocks when the buffer is full. Shared memory provides no such guarantee, so it must be paired with semaphores, mutexes, futexes or atomic operations that order access to the common region.

Poor synchronization produces the classic concurrency failures. A race condition corrupts data when two writers interleave, a deadlock freezes processes that wait on each other in a cycle, and priority inversion lets a low-priority holder of a lock delay a high-priority waiter, a problem that matters especially in a real-time operating system.

  • Semaphores count available resources and block when the count reaches zero.
  • Mutexes grant exclusive ownership of a critical section to one holder at a time.
  • Futexes on Linux stay in user space when uncontended and enter the kernel only to sleep.
  • Condition variables let a process wait efficiently for a specific state change.

IPC across kernel architectures

The kernel design strongly shapes IPC performance. In a monolithic kernel, file systems and drivers run inside the kernel, so IPC is mostly used between applications. In a microkernel, services such as file systems and drivers run as separate user-space processes, which means nearly every operation becomes an IPC message. That is why microkernel research, notably the L4 family, focused on reducing IPC latency to a few hundred CPU cycles.

Kernel typeRole of IPCRepresentative mechanism
Monolithic kernelApplication-level cooperationPipes, sockets, shared memory in Linux
MicrokernelCore path for all system servicesSynchronous message passing in seL4 or QNX
Hybrid kernelMix of in-kernel services and message-based subsystemsMach ports in macOS, ALPC in Windows
How kernel type affects IPC

Higher-level frameworks build on these primitives. D-Bus carries desktop and system service messages on Linux, XPC structures service communication on macOS, COM and RPC over ALPC serve Windows components, and Binder is the central IPC path of Android.

Choosing an IPC mechanism in practice

The right mechanism depends on data volume, latency requirements, trust between parties and portability. Shared memory is worth its complexity only when measurements show that copying is the bottleneck.

SituationRecommended choiceReason
Chaining command-line toolsAnonymous pipeZero setup, inherited by child processes
Local service with many clientsUnix domain socket or named pipeConnection model, permission checks
Large frames at high rateShared memory plus semaphoreAvoids per-message copies
Services on different machinesNetwork socket or RPC frameworkOnly option that crosses hosts
Simple control eventSignal or event objectMinimal overhead for notification
Decision guide for IPC selection

Security must be designed in from the start. Every IPC endpoint is an attack surface: a privileged service that trusts messages from unprivileged clients without validation can be exploited to escalate privileges. Sound practice includes checking peer credentials, restricting endpoint permissions and treating all incoming data as untrusted input.

Limitations and common mistakes

IPC adds overhead and failure modes that do not exist inside a single process, because every channel can fail when a peer crashes.

  • Ignoring partial reads and writes on streams, which splits or merges messages unexpectedly.
  • Leaking IPC objects such as System V shared memory segments that persist after the creator exits.
  • Assuming shared memory is synchronized, which leads to torn reads and corrupted structures.
  • Blocking forever on a dead peer instead of using timeouts or detecting a closed connection.
  • Trusting unauthenticated clients of a privileged local service.

In simple terms

Programs on a computer live in separate rooms with locked doors, so one program cannot simply look into another one’s memory. Inter-process communication is the set of approved ways to pass things between those rooms. The operating system acts like a building manager who installs mail slots, intercoms and shared whiteboards.

A mail slot is like a pipe or message queue: one side drops something in, the other side picks it up. A shared whiteboard is like shared memory: very fast, but everyone must take turns writing or the result becomes a mess. The building manager keeps the doors locked while still letting the right programs cooperate.

A practical example

A team building a video surveillance application on Linux splits it into three processes: a capture process that reads frames from cameras, an analysis process that detects motion and a small web service that shows alerts. Each camera produces 1080p frames at 30 frames per second, roughly 180 MB of raw image data per second per camera.

Sending every frame through a socket would mean copying hundreds of megabytes per second through the kernel. The engineers instead place frames in a ring buffer in POSIX shared memory, guarded by semaphores that mark which slots are full or free, while the analysis process sends short alert messages to the web service over a Unix domain socket. The result is that CPU use for frame transfer drops to a small fraction, and a crash in the web service no longer takes the capture pipeline down with it.