编写我自己的玩具壳,并碰到试图执行作业控制的碰撞。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