Part 1 of 6 · 1 min read
Why this page comes seventh
In this module you will
- Create a pipe with
pipe, share it acrossfork, and send bytes from one process to another. - Explain end-of-file on a pipe and why unused ends must be closed.
- Build the equivalent of
ls /etc | wc -lwithfork,dup2andexec. - State how large a pipe's buffer is and what happens when it is full or has no reader.
- Name the main ways processes talk to each other and when each is used.
Page 4 used dup2 to point a command's output at a file. A pipe goes one step further and points the output of one process at the input of another. Page 3 showed why the gap between fork and exec is useful, and this page shows its best use. The next page finishes the level with the ways processes end and are cleaned up. The main sources are "The Linux Programming Interface" (TLPI), chapters 44 and 45, "Operating Systems: Three Easy Pieces" (OSTEP), chapter 5, and "Operating System Concepts" (OSC), chapter 3. All programs were compiled with -Wall -Wextra and run.
About this example About this example
Real: The C programs, commands and outputs on this page were compiled with gcc -Wall -Wextra -pthread and run on a Linux test machine (2 processors, kernel 6.18, glibc 2.39).
Scripted: The worked traces use small numbers chosen so they can be followed by hand.
Not real: The page simplifies real systems. Actual kernels add more cases, limits and tuning than a short page can show.