On Wed, Sep 11, 2002 at 07:22:28PM +0300, Nadav Har'El wrote:
> On Wed, Sep 11, 2002, Muli Ben-Yehuda wrote about "Re: tail(1) and char device 
>files":
> > No, that's not it. For !S_ISREG files, tail does the equivalent of:
> > 
> > while (read(...) > 0) {
> >       allocate a buffer 
> >       add what we read to the buffer
> >       continue
> > }
> > 
> > That loop will only terminate when tail runs out of memory (there's an
> > xmalloc() inside the loop) or when read returns 0 (EOF) or -1 (error),
> > and then tail will print everything. 
> 
> Why everything? It should only print the last 10 lines (by default)...
> Does it really save *the entire input* in memory, without any attempt
> to "forget" all lines that are not the last 10?

It's in gnu coding style, which makes it hard to follow... but it
looks like it indeed maintains a ring of buffers, dependant on the
number of lines you asked it to print and the number of newlines it
saw in the output. If your output has no new lines, it will grow until
OOM, as far as I can see. 

> > Yup, as is our character device. I'll see if I can find any mentions
> > of this behaviour from tail in POSIX. 
> 
> Because "tail -f" is supposed to print the last 10 lines *and* then continue
> to show everything else, what exactly "tail -f" does on a file that cannot
> be reopened is indeed a good question...
> I suppose that your suggestion (to have it be equivalent to "cat") might
> be more useful than the current behavior (equivalent to "tail" without -f),
> but maybe something is explicitly defined in the standard?
> 
> POSIX (or SUv3) is available online freely, by the way, so you might want
> to have a look.

I intend to, when I'll find the time :) 
-- 
Muli Ben-Yehuda
syscalltrack hacker-at-large

Attachment: msg21701/pgp00000.pgp
Description: PGP signature

Reply via email to