|
From: K-mart Cashier on 15 Jun 2008 02:23 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.
From: Erik de Castro Lopo on 15 Jun 2008 03:19 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
|
Pages: 1 Prev: Ryhm�n sfnet.urheilu virallinen kuvaus Next: When to use stderr, and when stdout? |