【发布时间】:2009-10-22 15:26:37
【问题描述】:
编写我自己的玩具外壳,但在尝试实现作业控制时遇到了麻烦。
我正在使用 setpgid 在子进程和父进程中设置子进程组。我的等待电话是:
pid = waitpid(-pid, &status, 0)
但是,waitpid 返回 -1 并且 perror 说“没有子进程”。但是,它似乎每次都在等待。此外, ps 输出看起来正确意味着从 shell 运行时。由于 ps parent 的进程是 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 上
-
忽略了 SIGCHILD,这就是它不起作用的原因:-P