Stdio buffering question

Chris Torek chris at mimsy.UUCP
Sat Jun 11 12:42:08 AEST 1988


In article <4999 at super.upenn.edu> david at linc.cis.upenn.edu (David Feldman)
writes:
>A self proclaimed novice asked why stderr gets buffered when piped in
>Sun OS 3.3.
>
>Well, I can give an answer based on Ultrix experience.  When piping,
>stderr gets buffered so that it may be separated from stdout.

No.  Buffering is a user-level concept; piping and descriptor
merging is a kernel level concept.  The two are not supposed to
to be mixed together.

Stderr gets buffered because it improves performance and raises
benchmark numbers.  It also makes correct programs fail, and should
not be done casually.

>...  That is assuming you have redirected stderr through the pipe also.
>This is a documented feature, and I believe it is a csh thing.

It has nothing to do with the shell being used.

>I don't think fflush() will help ...

It will.

>...  One way csh could implement this feature is to attach stderr to
>a file and then throw the file down the pipe when stdout closes.

This would generally destroy performance, as the shell would have to
remain in the path of a pipeline.  Currently `a |& b' simply runs a and
b `together' (under csh, a is started first) with a's stdout and stderr
(fds 1 and 2) both going to a pipe that is b's stdin (fd 0).  The
pipe is created with kernel concepts (file descriptors) and the
programs are run without giving them any knowledge as to where those
descriptors connect.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list