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 @R_269_4045@ion 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);
}

相关文章

/etc/sysctl.conf这个目录主要是配置一些系统信息,/etc/sys...
1.作用 useradd或adduser命令用来建立用户帐号和创建用户的起...
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅...
不管是我们在安装软件还是监测软件的使用性能,我们都要随时...
装好Tomcat7后,发现除了本机能访问外界访问不了,岂有此理。...
修改防火墙配置需要修改 /etc/sysconfig/iptables 这个文件,...