On 2/24/20 5:18 PM, Chet Ramey wrote:
The first case is trickier: there's always going to be a window between the time the shell checks for pending traps and the time the wait builtin starts to run. You can't really close it unless you're willing to run the trap out of the signal handler, which everyone agrees is a bad idea, but you can squeeze it down to practially nothing.
dash uses something along these lines: sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, &mask); while (!pending_sig) sigsuspend(&mask); sigprocmask(SIG_SETMASK, &mask, NULL); if (pending_sig) handle_signals(pending_sig); pid = waitpid(... WNOHANG); It sleeps in sigsuspend(), not in waitpid(). This way we wait for both signals *and* children (by virtue of getting SIGCHLD for them).