I don't understand quite well what you try to ask, but as you have been already told, pipes are not more than buffer.
Historically, fifos (or pipes) consumed the direct blocks of the inode used to maintain them, and they tied to a file (having it a name or not) in some filesystem.
Today, I don't know the exact implementation details for a fifo, but basically, the kernel buffers all data the writers have already written, but the readers haven't read yet. The fifo has an upper limit (system defined) for the amount of buffer they can support, but normally that fails around 10-20kb of data.
The kernel buffers, but there's no delay between writers and readers, because as soon a writer writes on a pipe, the kernel awakens all the readers waiting for it to have data. The reverse is also true, in the case the pipe gets full of data, as soon as a reader consumes it, all the writers are awaken to allow for filling it again.
Anyway, your question about flushing has nothing to do with pipes (well, not like, let me explain myself) but with <stdio.h>
package. <stdio.h>
does buffer, and it handles buffering on each FILE *
individually, so you have calls for flushing buffers when you want them to be write(2)
n to disk.
has a dynamic behaviour that allows to optimize buffering and not force programmers to have to flush at each time. That depends on the type of file descriptor associated with a FILE *
pointer.
When the FILE *
pointer is associated to a serial tty (it does check that calling to isatty(3)
call, which internally makes an ioctl(2)
call, that allow <stdio.h>
to see if you are against a serial device, a char device. If this happens, then <stdio.h>
does line buffering that means that always when a '\n'
char is output to a device, the buffer is automatically buffered.
This supposes an optimization problem, because when, for example you are using cat(1)
to copy a file, the largest the buffer normally supposes the most efficient approach. Well, <stdio.h>
comes to solve the problem, because when output is not a tty device, it makes full buffering, and only flushes the internal buffers of the FILE *
pointer when it is full of data.
So the question is: How does <stdio.h>
behave with a fifo (or pipe) node? The answer is simple.... is is not a char device (or a tty) so <stdio.h>
does full buffering on it. If you are communicating data between two processes and you want the reader to receive the data as soon as you have printf(3)
ed it, then you have better to fflush(3)
, because if you don't, you can be waiting for a response that never comes, because what you have written, has not yet been written (not by the kernel, but by the <stdio.h>
library)
As I said, I don't know if this is exactly the answer to your question, but for sure it can give you a hint on where the problem could be.