09-21-05 01:49 AM
On Wed, 21 Sep 2005, Guillaume Vasselin wrote:
[vbcol=seagreen]
> I'm a beginner both in C and unix. I wrote a toy program where a process
> sends through a pipe a single character every second, with the child
> printing them on stdout.
> I wanted the output te be one character every second, but they are
> printed all at once.
>
> Given my lack of knowledge, I highly suspect errors on my side, but I
> need to be sure if that's the kind of thing you can do with pipes. I did
> some research on how they work exactly, but what I found wasn't very clear.[/vbcol
]
The reason why you're seeing the behaviour you describe is because you're
using the standard I/O library (putchar et al), which for efficiency buffers
I/O. Try replacing your putchar and getchars with read and write (which
are not buffered).
In short: your program is sound, but you're being bitten by the standard
I/O library buffering.
HTH,
--
Rich Teer, SCNA, SCSA, OpenSolaris CAB member
President,
Rite Online Inc.
Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich
[ Post a follow-up to this message ]
|