Reap N-number of children per SIGCHLD

Este commit está contenido en:
Lester Hightower 2024-07-02 09:33:43 -04:00
padre 250e2ae24f
commit 5236c8d947

Ver fichero

@ -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);
@ -742,6 +747,7 @@ void child_handler(int signum, siginfo_t *info, void *context)
adhocify_exit_code = 128 + WTERMSIG(status); // copy bash's behaviour adhocify_exit_code = 128 + WTERMSIG(status); // copy bash's behaviour
exit(adhocify_exit_code); exit(adhocify_exit_code);
} }
}
} }
void set_signals() void set_signals()