3 ms·
The best thing to do in a signal handler is often to write() a single byte to a pipe. Your main loop can then notice that the other end of the pipe is readable
by caf 15y ago
The best thing to do in a signal handler is often to write() a single byte to a pipe.
Your main loop can then notice that the other end of the pipe is readable (the main loop is normally watching file descriptors for activity anyway).
- gchpaco 15y agoThat's a good point, and what I actually did last time this came up. signalfd on Linux just codifies this convention, but it is (particularly in evented code) an excellent idea.
- emmelaich 15y agoI believe this is referred to as the 'self pipe' trick. Dan Bernstein says he came up with it in 1990. http://cr.yp.to/docs/selfpipe.html http://cr.yp.to/docs/selfpipe.html