创建子进程并立即退出(_exit())后,我想执行等待并检查状态。现在我想知道在 if/else 构造的“else”分支中是否还需要检查 WIFSIGNALED。据我了解,如果我执行等待,a) 可能发生错误 (-1),子进程可能已由 (exit() 或 _exit()) 正常终止,或者它可能已被终止信号,所以检查可以省略,对吧?
//remainder omitted
int status;
pid_t t_pid = wait(&status);
if (t_pid == -1) {
perror("wait");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("child terminated normally, status = %d\n",
WEXITSTATUS(status)
);
} else { // <-- do it have to check for WIFSIGNALED() here?
printf("child was terminated by a signal, signum = %d\n",
WTERMSIG(status)
);
}