#include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { char *plop[2]; procctl(P_PID, getpid(), PROC_REAP_ACQUIRE, NULL); pid_t pid; int pstat; struct procctl_reaper_status info; plop[0] = "sh"; plop[1] = NULL; if ((pid = fork()) == 0) execvp("/bin/sh", argv); procctl(P_PID, getpid(), PROC_REAP_STATUS, &info); printf("%s: %d\n", "la", info.rs_children); while (waitpid(pid, &pstat, 0) == -1) { if (errno != EINTR) break; } printf("%s\n", "la2"); procctl(P_PID, getpid(), PROC_REAP_STATUS, &info); while (info.rs_children > 0) { printf("====>%d\n", info.rs_children); printf("====>%d: killing %d\n", getpid(), info.rs_pid); kill(info.rs_pid, SIGTERM); while (waitpid(info.rs_pid, &pstat, 0) == -1) { if (errno != EINTR) err(1, "plop"); } procctl(P_PID, getpid(), PROC_REAP_STATUS, &info); } }