編寫我自己的玩具殼,並碰到試圖執行作業控制的碰撞。waitpid()在等待進程組時出現無子進程錯誤
我正在設置孩子的過程組,同時使用setpgid設置孩子和父母的過程組。我的等待電話是:
pid = waitpid(-pid, &status, 0)
但是,waitpid返回-1,perror表示「沒有子進程」。但是,它似乎每次都在等待。另外,從shell輸出時,ps輸出看起來是正確的。由於ps父母的過程像我期望的那樣是kbsh。
% ps -o pid,ppid,pgrp,session,tpgid,comm
Forking
In Parent: Setting process group to 20809 of process 20809 with setpgid
In Child Processes, pid of child process is 20809
in Child: Setting process group to 20809 of process 20809 with setpgid
Requesting that Process Group 20809 becomes the foreground process with tcsetpgrp
Waiting for job with process group 20809
PID PPID PGRP SESS TPGID COMMAND
12002 32573 12002 12002 20809 zsh
20808 12002 20808 12002 20809 kbsh
20809 20808 20809 12002 20809 ps
Wait Error: No child processes
Restoring Shell process group 20808 to forground
有人看到我在做什麼錯了嗎?如果需要可以發佈更多代碼...
似乎與-1以及-pid – 2009-10-22 16:15:42
當時ignorning SIGCHILD發生,那就是它不工作的原因:-P – 2009-10-22 18:02:00