#include <stdio.h> #include <sys/wait.h> void sig_chld(int signo) { pid_t pid; int stat; while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) { printf("child %d terminated\n", pid); } return; }
注:选项WNOHANG告知waitpid在尚有未终止的子进程在运行时不要阻塞
原文:https://www.cnblogs.com/soldierback/p/10696253.html