[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Head too greedy

From: Eric Blake
Subject: Re: Head too greedy
Date: Mon, 01 Jan 2007 17:39:58 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061207 Thunderbird/ Mnenhy/

Hash: SHA1

According to John Summerfield on 1/1/2007 5:58 AM:
> In this example, the results are what I desire. However,
> address@hidden ~]$ yes stuff | head -300 | cat -n | (head -2;tail -2)
>      1  stuff
>      2  stuff
> address@hidden ~]$ 
> I presume this arises because head's reading ahead (if not head, then
> glibc on head's behalf), and when head's printed enough lines it simply
> closes its files (or maybe just exit()s.

This behavior is allowed by POSIX.  If stdin is seekable, POSIX requires
that head (and any other utility that consumes partial input) rewind to
the last character consumed before exiting; but when stdin is a pipe,
there is no guarantee, and even an explicit statement that compliant
programs must not rely on the amount of data read ahead by the first
program in the pipeline.  Programs are more efficient with buffering, so
we do not want to change head to turn buffering off; and there are just to
many programs that could be told to disable buffering to add something
like --unbuffered to each of them.  That said, there has been a proposal
on this list in the past to write a new wrapper utility (somewhat like
nohup or nice are wrapper utilities) that disables buffering of the
std{in,out} of the wrapped program.  If someone were to write such a
program, it would be the perfect candidate for use in the scenario you

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]