当前位置: 技术问答>linux和unix
【求助】子进程中调用raise(SIGSTOP)的问题
来源: 互联网 发布时间:2017-01-10
本文导语: 本帖最后由 Redshadows 于 2011-10-22 18:14:53 编辑 int main(int argc, char *argv[]) { int sockfd, err, n; pid_t child_pid; if ( (child_pid = fork()) == 0) { ...
int
main(int argc, char *argv[])
{
int sockfd, err, n;
pid_t child_pid;
if ( (child_pid = fork()) == 0) {
printf("child before raisen");
raise(SIGSTOP);
printf("child exitn");
exit(0);
} else {
printf("child pid is %dn", child_pid);
sleep(1);
kill(child_pid, SIGCONT);
printf("parent exitn");
}
exit(0);
}
上面代码运行的结果是:
child pid is 2752
child before raise
parent exit
child exit
父进程sleep一秒钟后,发信号给子进程使其继续运行,正确。
int
main(int argc, char *argv[])
{
int sockfd, err, n;
pid_t child_pid;
if ( (child_pid = fork()) == 0) {
printf("child before raisen");
raise(SIGSTOP);
printf("child exitn");
exit(0);
} else {
printf("child pid is %dn", child_pid);
sleep(1);
printf("parent exitn");
}
exit(0);
}
但当我把父进程的kill语句删除掉以后,运行结果为:
child pid is 2863
child before raise
parent exit
此时执行ps,发现:
PID TTY TIME CMD
1976 pts/0 00:00:00 bash
2864 pts/0 00:00:00 ps
请问,既然子进程在raise(SIGSTOP)处停止,而父进程也没有向其发送继续的信号,为何子进程消失了,而不是一直被挂起?
难道是父进程结束后,子进程被init接收后被结束掉???
不懂,求各位指点一下,谢谢~~
|
楼主的代码无形中产生了zombin,因为你没join.
ps aux | grep 2863看看?
ps aux | grep 2863看看?