bug-coreutils
[Top][All Lists]
Advanced

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

Re: Cat and -u, unbuffered output support


From: Bob Proulx
Subject: Re: Cat and -u, unbuffered output support
Date: Tue, 24 Jun 2003 01:55:45 -0600
User-agent: Mutt/1.3.28i

Scott Bronson wrote:
> Thanks for the reply, Bob!  Maybe I'm misunderstanging the meaning of
> "unbuffered".  First, the vital statistics:
>    address@hidden:~$ cat --version
>    cat (coreutils) 5.0

Very good.  Thanks.

> Here's an illustration that can be run in a single shell:
> 
>    % mkfifo fi
>    % cat -u fi &
>    % cat -u > fi

Ah, now I understand.

> Now, if cat wrote each byte from the input to the output without delay,
> then typing "abc\n" into the fifo would produce "aabbcc\n\n" on the
> screen.  Each character would be sent through the pipe and echoed
> immediately.

But there _is_ someplace where the input is being buffered.  It is the
tty line driver.  It is what implements your ability to "back up" and
delete characters implementing what is known as canonical imput mode.

> However, the result of typing "abc\n" is "abc\nabc\n".  This implies
> that SOMEBODY (perhaps I was too hasty in implicating cat) is buffering
> the bytes up to the newline, then sending them in one big burst.  Is
> this the expected behavior?

Modify your experiment this way:

   % mkfifo fi
   % cat -u fi &
   % stty raw
   % cat -u > fi

It will be difficult to use a raw terminal.  And you will probably
need to kill the cat from another terminal since in raw mode there
will be no eof processing.  But in this mode you should see the aabbcc
mode you were thinking you should be getting.

Either Stevens with Advanced Programming in the UNIX Environment or
Rochkind with Advanced UNIX Programming would be my references for
detailed information about the tty driver.  But I am sure it is
documented elsewhere too.

Bob




reply via email to

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