由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - A question related to pipe
相关主题
Python有什么好的方法建two-way pipe?how can I get external program's result in C
PyCharm里的Python启动的Process在等待按键,如何继续菜鸟请教个hadoop streaming job 的问题 (转载)
请教一个python下面popen的问题编写支持CGI的web服务器大致原理 (转载)
Python里边file writer的问题50伪币:请教perl代码差错的问题!多谢啦!
does the system guarantee this? (转载)请高人解释一下为啥这个输出总是"HELLO-ERR"
想实现一个简单的script language,用perl好做么?一个 perl 的 print 的初级问题
问一个vc++ 2008的问题node.js multer: Recursive process.nextTick detected
高人帮我看看一个简单的script,为什么nohup有问题? (转载)node.js child process: 怎样保证1个命令执行完了再执行下一个?
相关话题的讨论汇总
话题: pipe话题: p2话题: p1话题: question话题: read
进入Programming版参与讨论
1 (共1页)
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
5
use flush
1 (共1页)
进入Programming版参与讨论
相关主题
node.js child process: 怎样保证1个命令执行完了再执行下一个?does the system guarantee this? (转载)
is perror() non-buffered io in linux ? (转载)想实现一个简单的script language,用perl好做么?
请问如何恢复正常的IO?问一个vc++ 2008的问题
大家帮我看看C文件输入函数fprintf的问题高人帮我看看一个简单的script,为什么nohup有问题? (转载)
Python有什么好的方法建two-way pipe?how can I get external program's result in C
PyCharm里的Python启动的Process在等待按键,如何继续菜鸟请教个hadoop streaming job 的问题 (转载)
请教一个python下面popen的问题编写支持CGI的web服务器大致原理 (转载)
Python里边file writer的问题50伪币:请教perl代码差错的问题!多谢啦!
相关话题的讨论汇总
话题: pipe话题: p2话题: p1话题: question话题: read