作者Lee1027 (遇到吠狗真衰)
看板C_and_CPP
标题Fw: [问题] unnamed pipe IO 问题
时间Sat Nov 7 01:44:51 2015
※ [本文转录自 Linux 看板 #1MF8BAzw ]
作者: Lee1027 (遇到吠狗真衰) 看板: Linux
标题: [问题] unnamed pipe IO 问题
时间: Fri Nov 6 18:36:54 2015
大家好,我手边有个测试pipe buffer 大小的小程式
code 在perant 的地方会一直塞一个字元a到buffer直到塞满为止
我的问题是为什麽跑到一半都会终止
为什麽child 那边一定要等才可以完整测完整个pipe
int main()
{
int i;
int pfd[2];
int ret = pipe(pfd);
if (ret != 0) {
perror("pipe");
exit(-1);
}
pid_t pid = fork();
if (pid == 0) { //child process
close(pfd[1]);
//pause();
return 0;
}
else if (pid > 0) { //parent process
close(pfd[0]);
char buf[] = "a";
for (i = 0; ; i++) {
write(pfd[1], buf, sizeof(buf[0]));
printf("write pipe %d, total %d\n", i+1, (i+1)*sizeof(buf[0]));
}
pid_t cpid = waitpid(-1, NULL, 0);
//return 0;
} else {
perror("fork");
}
printf("last line\n"); //debug used
return 0;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.251.223.31
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Linux/M.1446806218.A.F7A.html
※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: Lee1027 (118.161.157.120), 11/07/2015 01:44:51
1F:推 yvb: man 7 signal ==> SIGPIPE 11/07 03:51
2F:→ Lee1027: 3Q 11/07 14:59