s********g 发帖数: 13 | 1 i have two programs, P1 print one line of data to stdout every 1 sec.
P2 read in data from stdin and do some processing, now I am using pipe
as follows in linux:
P1 | P2
what happens is that P2 is not getting data from the pipe every sec, it
seems
that it wait for the pipe to be filled full by P1, and read a lot of lines
out.
My question is: why the pipe performs like this way? wouldn't P2 should
read one line as soon as it sees a '\n'? | t****t 发帖数: 6806 | 2 usually, all streams are block buffered, unless:
if it is stderr, it's unbuffered
if it is not stderr, and refers to a terminal, it is line buffered.
you may change the behaviour by using setbuf().
【在 s********g 的大作中提到】 : i have two programs, P1 print one line of data to stdout every 1 sec. : P2 read in data from stdin and do some processing, now I am using pipe : as follows in linux: : P1 | P2 : what happens is that P2 is not getting data from the pipe every sec, it : seems : that it wait for the pipe to be filled full by P1, and read a lot of lines : out. : My question is: why the pipe performs like this way? wouldn't P2 should : read one line as soon as it sees a '\n'?
| s********g 发帖数: 13 | 3 I guess i don't understand why pipe does not behave like stdout,
for stdout, the buffer is flushed either when the buffer is full or it
sees a '\n'. Pipe will not be flushed even P1 puts a '\n' at the end of
each line.
【在 t****t 的大作中提到】 : usually, all streams are block buffered, unless: : if it is stderr, it's unbuffered : if it is not stderr, and refers to a terminal, it is line buffered. : you may change the behaviour by using setbuf().
| t****t 发帖数: 6806 | 4 because pipe does not refer to a terminal, of course! can't you read?...
【在 s********g 的大作中提到】 : I guess i don't understand why pipe does not behave like stdout, : for stdout, the buffer is flushed either when the buffer is full or it : sees a '\n'. Pipe will not be flushed even P1 puts a '\n' at the end of : each line.
| c********x 发帖数: 84 | |
|