How do I keep a pipe from buffering I/O?

Doug Gwyn gwyn at smoke.brl.mil
Thu Feb 28 08:30:49 AEST 1991


In article <1585 at gufalet.let.rug.nl> bert at let.rug.nl (Bert Bos) writes:
>Problem is, the pipes appear to buffer such large amounts of text,
>that one process only gets input after the other has already finished.
>How do I force the pipes to pass on text one line at a time?
>I'm using calls such as pipe(), dup2(), select(), read(), etc, but I
>couldn't find anything in the manuals.

Since (unless your pipe implementation is horribly broken) each write()
produces an independent chunk in the pipeline, I would guess that what
you are actually having trouble with is buffering in the applications,
not in the kernel.  If stdio is being used, be sure to fflush() the
output to ensure that it is write()n to the pipe, and use setbuf() to
disable input buffering on the reader.  Obviously, if either or both
of the communicating processes are provided by somebody else, you may
not be able to change how they operate.



More information about the Comp.unix.programmer mailing list