kqueues for Signal Handling
Unix signals, due to their asynchronous nature, are difficult to handle correctly. Race conditions are possible, plus you have to be aware of functions you can or can’t call at signal interrupt time. Most of the time, you really do not have to handle a signal the instant it is delivered. You can handle it later at a more convenient time. That is why a common signal handling technique is to set a global variable and then check it later.
You can use kqueues and kevent() to handle signals, saving you from the headaches caused by the signal handling API. The filter for signals is also one of the simplest of the kqueue filters.
kqueue event handling can be used in tandem with the classic signal handling API. Calls like ...
Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.