What is "Piping"?

Pipe accepts the output of one command, and feeds it as an input to the next command.
eg: ls | wc -l

Output of 'ls' is fed as input to wc-l. Hence wc counts the number of lines in the result of ls.

Showing Answers 1 - 1 of 1 Answers

Rahul Shukla

  • May 8th, 2006
 

piping:- sending the output of a command to the input of another is called piping.

some examples are:

$cal | wc

will output total line's,word's and character's

$cal | wc | wc

will output total line's,word's and character's

A unix pipe provides a one-way flow of data.

for example

  • For example, if a Unix users issues the command
    $who | sort |lpr	
    then the Unix shell would create three processes with two pipes between them:
  • A pipe can be explicitly created in Unix using the pipe system call. Two file descriptors are returned--fildes[0] and fildes[1], and they are both open for reading and writing. A read from fildes[0] accesses the data written to fildes[1] on a first-in-first-out (FIFO) basis and a read from fildes[1] accesses the data written to fildes[0] also on a FIFO basis.

  • When a pipe is used in a Unix command line, the first process is assumed to be writing to stdout and the second is assumed to be reading from stdin. So, it is common practice to assign the pipe write device descriptor to stdout in the first process and assign the pipe read device descriptor to stdin in the second process. This is elaborated below in the discussion of multiple command pipelines.

  • Give your answer:

    If you think the above answer is not correct, Please select a reason and add your answer below.

     

    Related Answered Questions