Tag: sigchld

不想立即删除终止子进程,需要成为僵尸

我从SE QUE获得以下信息明确地将SIGCHLD的处置设置为SIG_IGN会导致随后终止的任何子进程立即从系统中删除而不是转换为僵尸。 据我所知,要读取子状态,需要在进程表中使用子进程。 因此有必要在进程表中使用zombie子进程来读取子状态。 所以我想编写信号处理程序,它将删除“将SIGCHLD的处置设置为SIG_IGN” 我使用下面的代码(在fork之前)以避免在终止后立即删除子进程:但我仍然无法获得子状态并且waitpid使用ECHILD返回-1。 #include #include #include #include #include #include static siginfo_t sig_info; static volatile sig_atomic_t sig_num; static void *sig_ctxt; static void catcher(int signum, siginfo_t *info, void *vp) { sig_num = signum; sig_info = *info; sig_ctxt = vp; } static void set_handler(int signum) { struct sigaction sa; sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = catcher; […]

我该如何处理SIGCHLD?

我需要正确处理SIGCHLD 。 如何在现有代码中使用它。 目前我不能等待子进程,除非我使用0而不是WNOHANG|WUNTRACED 。 status = 0; pid_t child, endID; if(amp == 1) signal( SIGCHLD, SIG_IGN ); child = fork(); if (child < 0) { perror("fork() error\n"); exit(EXIT_FAILURE); } else if (child == 0) { // do sth here perror("error\n"); } else { //sleep(1) 如果我删除sleep然后父亲被执行1 ..为什么?