Pipes are an interprocess communication mechanism that is provided in all flavors of Unix. A pipe is a one-way flow of data between processes: all data written by a process to the pipe is routed by the kernel to another process, which can thus read it.
In Unix command shells, pipes can be created by means of the | operator. For instance, the following statement instructs the shell to create two processes connected by a pipe:
$ ls | more
The standard output of the first process, which executes the ls program, is redirected to the pipe; the second process, which executes the more program, reads its input from the pipe.
Note that the same results can also be obtained by issuing two commands such as the following:
$ ls > temp $ more < temp
The first command redirects the output of ls into a regular file; then the second command forces more to read its input from the same file. Of course, using pipes instead of temporary files is usually more convenient since:
The shell statement is much shorter and simpler.
There is no need to create temporary regular files, which must be deleted later.
Pipes may be considered open files that have no corresponding image in the mounted filesystems. A new pipe can be created by means of the pipe( ) system call, which returns a pair of file descriptors. The process can read from the pipe by using the read( ) system call with the first file descriptor; likewise, it can write into the pipe by using the write( ) system ...