Inter-Process Communication: Pipes
In Chapter 11, you saw a very simple way of sending messages between two processes using signals. You created notification events that could be used to provoke a response, but the information transferred was limited to a signal number.
In this chapter, you take a look at pipes, which allow more useful data to be exchanged between processes. By the end of the chapter, you’ll be using your newfound knowledge to re-implement the CD database program as a very simple client/server application.
We cover the following topics in this chapter:
- The definition of a pipe
- Process pipes
- Pipe calls
- Parent and child processes
- Named pipes: FIFOs
- Client/server considerations
What Is a Pipe?
We use the term pipe to mean connecting a data flow from one process to another. Generally you attach, or pipe, the output of one process to the input of another.
Most Linux users will already be familiar with the idea of a pipeline, linking shell commands together so that the output of one process is fed straight to the input of another. For shell commands, this is done using the pipe character to join the commands, such as
cmd1 | cmd2
The shell arranges the standard input and output of the two commands, so that
- The standard input to cmd1 comes from the terminal keyboard.
- The standard output from cmd1 is fed to cmd2 as its standard input.
- The standard output from cmd2 is connected to the terminal screen.
What the shell has done, in effect, is reconnect the ...