Basicaly,我只能管結束我寫在C殼.. 我試着去實現管道功能,它幾乎做到了:爲什麼當我發送SIGINT
> ls | cat -e | wc | wc -l
> 1
但我有一個問題,當試圖製造更慢/更長的執行。
事實上,當我嘗試管的結果, '貓的/ dev/urandom的',它basicly等待...
> cat /dev/urandom | cat
>
但是,當我發送一個SIGINT(用CTRL + C)停止它,然後它打印在標準輸出上所得到的緩衝..
when i ctrl + c , cat /dev/urandom
所以我的問題是:我應該在哪裏尋找在嘗試解決這一問題?
我的菸斗執行部分:
int exec_apipe(t_me *me, t_node *curs, int is_last)
{
int pfd[2];
int pid;
if (pipe(pfd) == -1 || !curs)
return (0);
if (!(curs->pid = fork()))
{
dup2(me->fd_in, 0);
me->fd_in > 0 ? close(me->fd_in) : 0;
if (!is_last)
dup2(pfd[1], 1);
else if (curs->parent->parent && curs->parent->parent->fd_out >= 0)
dup2(curs->parent->parent->fd_out, 1);
close(pfd[0]);
exec_mpipe(me, curs);
exit(-1);
}
else if (curs->pid > 0)
{
waitpid(curs->pid, &(curs->ret), WUNTRACED);
handle_pid(me, curs->ret);
close(pfd[1]);
me->fd_in = pfd[0];
}
return (pid >= 0 ? 1 : -1);
}
我希望有人會明白什麼即時消息說,也許能幫助.. 感謝
閱讀所有upvoted的答案:http://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe –