[問題] unnamed pipe IO 問題
※ [本文轉錄自 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://www.ptt.cc/bbs/Linux/M.1446806218.A.F7A.html
※ 發信站: 批踢踢實業坊(ptt.cc)
※ 轉錄者: Lee1027 (118.161.157.120), 11/07/2015 01:44:51
推
11/07 03:51, , 1F
11/07 03:51, 1F
→
11/07 14:59, , 2F
11/07 14:59, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章