4 ms·
This? http://cr.yp.to/docs/selfpipe.html http://cr.yp.to/docs/selfpipe.html > Richard Stevens's 1992 book ``Advanced programming in the UNIX environment'' says
by severine 8y ago
This? http://cr.yp.to/docs/selfpipe.html http://cr.yp.to/docs/selfpipe.html
> Richard Stevens's 1992 book ``Advanced programming in the UNIX environment'' says that you can't safely mix select() or poll() with SIGCHLD (or other signals). The SIGCHLD might go off while select() is starting, too early to interrupt it, too late to change its timeout.
Solution: the self-pipe trick. Maintain a pipe and select for readability on the pipe input. Inside the SIGCHLD handler, write a byte (non-blocking, just in case) to the pipe output. Done.
Of course, the Right Thing would be to have fork() return a file descriptor, not a process ID.