- 论坛徽章:
- 0
|
我写了个函数处理SIGCHLD,使用wait来cleanup子进程。
void clean_up_child_process (int signal_number)
{
/* Clean up the child process. */
int status;
wait(&status);
}
在main里面用sigaction来注册这个signal handler
/* Handle SIGCHLD by calling clean_up_child_process. */
struct sigaction sigchld_action;
memset(&sigchld_action, 0, sizeof (sigchld_action));
sigchld_action.sa_handler = &clean_up_child_process;
sigaction(SIGCHLD, &sigchld_action, NULL);
然后发现在主程序里,使用system()启动子程序后会进入clean_up_child_process,而且被block在wait()调用处。但是使用fork+exec的子程序不会。
高手知道是为什么吗? |
|