Pipes and FIFOs
Understand how anonymous pipes enable unidirectional communication between related processes such as a parent and child, and how named pipes (FIFOs) extend this concept to unrelated programs through a file-system-based channel.
We'll cover the following...
In the previous lesson, we learned that separate processes cannot directly share variables because each process runs in its own protected memory space. We also introduced fork(), which creates a parent and a child process that execute independently.
We now ask a practical question: How can a parent and child process exchange data? One of the simplest mechanisms provided by the operating system is the pipe.
What is a pipe?
A pipe is a unidirectional communication channel that allows data to flow from one process to another. Unidirectional means data travels in one direction only; one end is used for writing, and the other end is used for reading.
Internally, a pipe is managed by the kernel and uses file descriptors. When a pipe is created, the operating system returns two file descriptors:
A read descriptor
A write descriptor
Anything written to the write end can be read from the read end.
Anonymous pipes
An anonymous pipe is created using the pipe() system call: