創建子進程並立即退出(_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)
);
}
+1尼斯鏈接的方式^^ – helpermethod 2010-03-29 13:08:42