Is there a way to obtain siginfo_t
struct when handling signals with kqueue
?
(On Linux when handling signal with epoll
similar struct signalfd_siginfo
is obtained by simply reading from signalfd
)
It's unfortunately not possible.
Signal delivery notifications via kqueue
occurs after the process itself has already reacted to the signal; i.e. they are a post-delivery notification, rather than an in-delivery notification.
If the process receives multiple signals between calls to kevent
, then all the system does is aggregate the number of times the signal has been delivered in the data
field of the kevent
structure.
This means that there's no way to obtain the signal information as, by the time you've called the kevent
data, the signal has already been delivered to the process, and the signal details have been discarded. There is no internal mechanism that keeps a record of the underlying signal information which could be delivered by the kevent
.
I was reading some of the big nerd ranch book which seems to indicate that the kqueue handling for signals would not occur if there was a handler registered for the process. This does not appear to be the behaviour on Yosemite, you receive the event for signals even if there is a handler registered using either
sigaction
orsignal
.