c – linux fork – execl,执行的进程变成了僵尸

我正试图从子进程运行twinkle命令行.
例如这样:

int hangup() {
write_on_display("line3","            ");
write_on_display("hide_icon","DIALTONE");
write_on_display("hide_icon","BACKLIGHT");

int pid = fork();
if (pid == 0) {
    int res = execl("/usr/bin/twinkle"," ","--immediate","--cmd","answerbye",(char *) NULL);
    _exit(0);
} else {
    perror("hangup");
    return 0;
}
return 1;
}

但闪烁变成僵尸:

10020 pts/1    Z+     0:00 [twinkle] <defunct>
10040 pts/1    Z+     0:00 [twinkle] <defunct>
10053 pts/1    Z+     0:00 [twinkle] <defunct>
10064 pts/1    Z+     0:00 [twinkle] <defunct>
10097 pts/1    Z+     0:00 [twinkle] <defunct>
10108 pts/1    Z+     0:00 [twinkle] <defunct>
10130 pts/1    Z+     0:00 [twinkle] <defunct>

我试着设定
信号(SIGCHLD,SIG_IGN);
但没有成功.
实际上我认为儿童过程在闪烁结束之前就已经死了.

从命令行运行闪烁如:

twinkle --immediate --call 100

不会使僵尸 – 闪烁正确关闭.
那里我想念的是什么?

最佳答案
父进程需要使用子进程ID调用waitpid().从链接的参考页面

All of these system calls are used to wait for state changes in a child of the calling process,and obtain information about the child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child,performing a wait allows the system to release the resources associated with the child; if a wait is not performed,then the terminated child remains in a “zombie” state (see NOTES below).

例如:

pid_t pid = fork();
if (0 == pid)
{
    /* Child process. */
}
else
{
    /* Parent process,wait for child to complete. */
    int status;
    waitpid(pid,&status,0);
}

相关文章

在Linux上编写运行C语言程序,经常会遇到程序崩溃、卡死等异...
git使用小结很多人可能和我一样,起初对git是一无所知的。我...
1. 操作系统环境、安装包准备 宿主机:Max OSX 10.10.5 虚拟...
因为业务系统需求,需要对web服务作nginx代理,在不断的尝试...
Linux模块机制浅析 Linux允许用户通过插入模块,实现干预内核...
一、Hadoop HA的Web页面访问 Hadoop开启HA后,会同时存在两个...