[cs631apue] question about pipeline
    Jan Schaumann 
    jschauma at stevens.edu
       
    Mon Dec  8 21:41:46 EST 2014
    
    
  
zding4 <zding4 at stevens.edu> wrote:
> When we deal with pipeline, like
> cmd1 | cmd2 | cmd3
>
> Should our shell wait for all 3 cmd?
Your shell should wait for the pipeline.  How the pipeline is terminated
may depend on the interactions of the commands in the pipeline.
> please check the commands below
> $ sleep 10 | echo hello (this case shell will output hello and will also  
> wait for sleep cmd)
'echo' is a command that does not read input from stdin, so it can
execute right away and then terminate, closing the read-end of the pipe.
'sleep' does not produce any output, so will run even though there is no
reader on the pipe.
> $ ls -R / | echo hello 
'echo' is a command that does not read input from stdin, so it can
execute right away and then terminate, closing the read-end of the pipe.
'ls -R /' produces output to stdout, which in this case is redirected
into the pipe.  Since there is no reader on the other side of the pipe,
the 'ls' process will receive SIGPIPE and terminate.
Try the same with 'cat' instead of 'echo'.
-Jan
    
    
More information about the cs631apue
mailing list