Skip to content

36. IPC — Pipes

A pipe is a unidirectional channel between two processes — the simplest IPC.

Internals: a kernel-managed circular buffer (~64KB on Linux). Full buffer blocks the writer; empty buffer blocks the reader — synchronization is automatic, no locks needed.

Anonymous pipes: only between related processes (parent-child), created with pipe(), no filesystem entry, die when both ends close.

Named pipes (FIFOs): have a filesystem name (mkfifo), can connect unrelated processes, persist until deleted.

Classic shell example: ls -l | grep ".txt" | wc -l — each | is a kernel pipe connecting one process's stdout to the next's stdin.

Key behaviors: blocking on empty/full; all writers closed → reader gets EOF; all readers closed → writer gets SIGPIPE; writes ≤ PIPE_BUF (4KB on Linux) are atomic.

Both pipes and message queues are unidirectional — for two-way communication you need two of them. Sockets and shared memory are bidirectional by nature.