What is a Pipe, and what is the difference between a Named and Unnamed pipe?
Last updated
A pipe is a unidirectional IPC channel where one process writes bytes and another reads them in FIFO order, acting like an in-kernel buffer. The distinction is naming: an unnamed pipe exists only between related processes, while a named pipe has a filesystem name so unrelated processes can use it.
Unnamed (anonymous) pipe:
Created with
pipe(); no name in the filesystem.Only usable between related processes (parent/child) that inherit the file descriptors via
fork().Vanishes when all descriptors are closed; this is what the shell
|operator uses.
Named pipe (FIFO):
Created with
mkfifo; appears as a special file with a path name.Unrelated processes can open it by name to communicate; persists in the filesystem until deleted.
Shared properties:
Byte-stream, FIFO order, fixed-size kernel buffer; a full buffer blocks the writer and an empty one blocks the reader.
Classic pipes are half-duplex (one direction); two are needed for bidirectional flow.