dear lazy web ... (UNIX pipes)

Mark Overmeer mark at overmeer.net
Sat Apr 19 15:52:25 BST 2008


* Greg McCarroll (greg at mccarroll.org.uk) [080419 14:40]:
> 
> now today i wondered about,
> 
>     process_that_generates_output | grep something | head
> 
> wondering if when head had enough output to make it happy it would
> terminate and that would propogate to grep and the first process.
> 
> and so i experimented timing the first process with and without head
> as the final pipe, and in a very unscientific test it came out with
> the same result.

The pipe is buffered in 4kB blocks by default.  Your process will
terminate if 'head' got its 4 kB from grep (or EOD).  Probably, grep
doesn't pass enough data through, such that the initial process has to
do all its work before head decides to quit and kill the pipe-line.
-- 
Regards,

               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net



More information about the london.pm mailing list