Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Does NEWLINE always flush stdio buffer? Message-ID: <1989Jul2.040259.3872@utzoo.uucp> Organization: U of Toronto Zoology References: <11012@ihlpl.ATT.COM> <12375@bloom-beacon.MIT.EDU> Date: Sun, 2 Jul 89 04:02:59 GMT In article <12375@bloom-beacon.MIT.EDU> scs@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@zoo.toronto.edu