Pipes
Definition:
A one-way data path between two processes:
Creation:
int fd[2]; int pipe(fd); fork(); ...
Two file descriptors are created: fd[0] for reading & fd[1] for writing. They are copied to the child process:
To construct the one-way pipe, the Parent process close its read fd and the child its write fd.
Piping many processes
The stdout of a process can be connected to the stdin of another through a pipe. For instance, that is what happens when the following shell command is executed:
who | sort | lpr
The shell program will use the pipe system call to create the following construction:
Two-way Connections
To create a two-way connection between process, two pipes have to be created. One in each direction:
Creation Sequence:
Parent Child Create Pipe 1 and Pipe 2 Fork Close read fd of Pipe1 Close write fd of Pipe1 Close write fd of Pipe2 Close read fd of Pipe 2 FIFO (named pipes)
Named Pipes are Pipes that have a name associated with them. They are used as data path between processes that are not related to each other.
Creation: They are created through the mknod call:
int mknod ( char *pathname, int mode, int dev);
pathname is the a common Unix pathname.
mode define the access mode
After creation, a FIFO can be opened like a file.