Re: fwrite over a pipe



K-mart Cashier wrote:

I was just browsing some of the old discussions in this forum when I
came across the following

http://groups.google.com/group/comp.unix.programmer/browse_thread/thread/9d7632464b8a0cc9/7f49ab361220d4fa?hl=en&lnk=st&q=fwrite+pipe+problem#7f49ab361220d4fa

And I quote

"Note that you must also be careful to flush writes onto pipes before
reading (and hence pending) for input. For example if you used
fprint or fwrite to output to the parent-to-child command pipeline,
it might not be on the actual pipe when you do a read of the child."

How could fprintf or fwrite() not be the actual pipe when it does a
read from the child? I can't think of an example at this time.

The fwrite and fprintf functions use buffered I/O. That means it
is legal for the implementation to internally buffer data without
actually writing to the underlying device regardless of whether that
device is a file on disk or a pipe.

The buffering of these functions can be modified (or even turned
off) using the setvbuf function. For instance, to turn buffering
off you should do:

setvbuf(strm, NULL, _IONBF, 0);

HTH,
Erik
--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"There are two ways of constructing a software design. One way is
to make it so simple that there are obviously no deficiencies
and the other is to make it so complicated that there are no
obvious deficiencies." -- C A R Hoare
.



Relevant Pages

  • Re: Design help...an explosion of interfaces......
    ... pipe is buffered are not; it is just loading or extracting from the pipe ... and call the right method with the right Pipe subclass instance. ... who understands the buffering context instantiate the relationship and ... the type attribute has a different semantics than the class ...
    (comp.object)
  • Re: stdout redirected to a processs own stdin
    ... Probably does not put anything in the pipe because output is buffered. ... > I suspect this is due to a misunderstanding of how pipes work. ... The UNIX system has no way of knowing about any ... turn off the output buffering with setbuf or flush the ...
    (comp.unix.programmer)
  • SUMMARY: Tru64 pipe buffer size
    ... The problem was that the application detected whether its stdout was going to file (pipe) or term, and did buffering in the case of a file. ... there was an easier way around the problem in our particular situation: Pipe the output via the tee command. ... Subject: Tru64 pipe buffer size ... We have a third-party tool which writes line-by-line to terminal device, but when its output is piped it seems to be buffering the data in chunks of approx 4KB at a guess. ...
    (Tru64-UNIX-Managers)
  • Re: circular buffering using substr() ?
    ... Can I use substr() to do circular buffering? ... stream from a pipe, which I need to send out on another pipe, but ... $offset); # OUTPIPE is non-blocking ...
    (comp.lang.perl.misc)
  • Re: pipe buffering
    ... read-end of pipe, ... the problem is with buffering, is there a way to disable buffering on pipe? ... are you using fflush in the child process? ...
    (microsoft.public.vc.language)