通常,您编写一个
SIGCHLD调用
waitpid()pid 的处理程序
-1。您可以使用返回值确定pid死了多少。例如:
void my_sigchld_handler(int sig){ pid_t p; int status; while ((p=waitpid(-1, &status, WNOHANG)) != -1) { }}struct sigaction sa;memset(&sa, 0, sizeof(sa));sa.sa_handler = my_sigchld_handler;sigaction(SIGCHLD, &sa, NULL);或者,您可以
waitpid(pid, &status,0)使用指定的子进程ID进行调用,并同步等待其终止。或用于
WNOHANG检查其状态而不会阻塞。



