Imagine I have a process that starts several child processes. The parent needs to know when a child exits.
I can use waitpid
, but then if/when the paren
I thought that select
will return EINTR
when SIGCHLD
signaled by on of the child.
I belive this should work:
while(1)
{
int retval = select(0, NULL, NULL, NULL, &tv, &mask);
if (retval == -1 && errno == EINTR) // some signal
{
pid_t pid = (waitpid(-1, &st, WNOHANG) == 0);
if (pid != 0) // some child signaled
}
else if (retval == 0)
{
// timeout
break;
}
else // error
}
Note: you can use pselect
to override current sigmask
and avoid interrupts from unneeded signals.