Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Using a self-pipe (signal handler writes one byte to one end, the other end is used in your event loop) is the most portable and reliable way to handle signals.


Yeah but it involves several extra syscalls, two file descriptors, and a kernel buffer that never has any actual data in it...

poll() + longjmp() out of the signal handler is actually surprisingly portable and much more efficient (but breaks all sorts of abstractions in ways that terrify people).


The overhead is very limited. The memory overhead is fixed, and the compute overhead is linear with the rate at which signals arrive (which is typically super low). Plus the whole thing is very easy to reason about. And you never have to worry about masking signals that you handle with a self-pipe. Add in the portability, and it's a very clear win.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: