Does NEWLINE always flush stdio buffer?

Henry Spencer henry at utzoo.uucp
Sun Jul 2 14:02:59 AEST 1989


In article <12375 at bloom-beacon.MIT.EDU> scs at adam.pika.mit.edu (Steve Summit) writes:
>... Line buffering partially removes the advantages of
>full buffering; it must not be turned on implicitly when
>batch-style jobs are generating large quantities of output
>redirected to a file.)

Unfortunately there is a further complication.  Terminal output definitely
should be line buffered or something similar.  (One can argue that doing
e.g. a single printf as one write, plus some care with fflush, ought to
be sufficient and actual line buffering causes more trouble than it is
worth.)  Disk output pretty definitely should be fully buffered.  But
what about pipes?  One really wants the final destination of output to
propagate back up a pipeline, so earlier stages use buffering appropriate
for the final destination.  In particular, a pipeline whose output is to
a terminal should *not* be doing full buffering at any stage.  This isn't
easy to do.  It might be reasonable to default to line buffering for pipes,
since modern Unixes very seldom implement them as anonymous disk files
(for which block alignment is a significant performance issue) and line
buffering gets you most of the performance win.
-- 
$10 million equals 18 PM       |     Henry Spencer at U of Toronto Zoology
(Pentagon-Minutes). -Tom Neff  | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list