Reap N-number of children per SIGCHLD

This commit is contained in:
Lester Hightower 2024-07-02 09:33:43 -04:00
parent 250e2ae24f
commit 5236c8d947

View File

@ -706,9 +706,14 @@ void child_handler(int signum, siginfo_t *info, void *context)
return; return;
} }
while (1) {
int status; int status;
pid_t p = waitpid(-1, &status, WNOHANG); pid_t p = waitpid(-1, &status, WNOHANG);
if(p == -1) if(p == 0) // No more children to reap
{
return; // exits infinite while loop and child_handler() function
}
if(p == -1) // waitpid error
{ {
logerror("waitpid failed when handling child exit\n"); logerror("waitpid failed when handling child exit\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -743,6 +748,7 @@ void child_handler(int signum, siginfo_t *info, void *context)
exit(adhocify_exit_code); exit(adhocify_exit_code);
} }
} }
}
void set_signals() void set_signals()
{ {