(Pipe): Communicates Between Processes


| (Pipe): Communicates Between Processes

Because pipes are integral to the functioning of a Linux system, they are introduced here for use in examples. Pipes are covered in detail beginning on page 216.

A process is the execution of a command by Linux (page 300). Communication between processes is one of the hallmarks of both UNIX and Linux. A pipe (written as a vertical bar, |, on the command line and appearing as a solid or broken vertical line on keyboards) provides the simplest form of this kind of communication. Simply put, a pipe takes the output of one utility and sends that output as input to another utility. Using UNIX/Linux terminology, a pipe takes standard output of one process and redirects it to become standard input of another process. (For more information refer to "Standard Input and Standard Output" on page 208.) Most of what a process displays on the screen is sent to standard output. If you do not redirect it, this output appears on the screen. Using a pipe, you can redirect the output so that it becomes instead standard input of another utility. For example, a utility such as head can take its input from a file whose name you specify on the command line following the word head, or it can take its input from standard input. Thus, you can give the command shown in Figure 5-5 on page 133 as follows:

$ cat months | head Jan Feb Mar Apr May Jun Jul Aug Sep Oct


The next command displays the number of files in a directory. The wc (word count) utility with the w option displays the number of words in its standard input or in a file you specify on the command line:

$ ls | wc -w 14


You can use a pipe to send output of a program to the printer:

$ tail months | lpr





A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net