Regarding Signal IPC
Jilles Tjoelker
jilles at stack.nl
Fri Jun 19 14:03:55 UTC 2009
On Fri, Jun 19, 2009 at 09:03:28AM -0400, Daniel Eischen wrote:
> On Fri, 19 Jun 2009, vasanth raonaik wrote:
> > I want to print out the process ID of the process which is sending the
> > Signal.
> > Is it possible. if yes, can you please point me to any related documents.
> Though I have not tried this, there is an si_pid field
> (and other fields you might be interested in) in
> struct siginfo. If you use a POSIX signal handler
> (see sigaction(2)), a pointer to a struct siginfo is
> the 2nd argument to your signal handler.
> See <sys/signal.h> for the definition of struct siginfo.
Meaningful siginfo is only given for signals sent by sigqueue(2), traps,
child processes (SIGCHLD) and sigevent structures (for example
mq_notify(2)).
If you want to handle signals synchronously, you can use
sigtimedwait(2). It is still necessary to call sigaction(2) with the
SA_SIGINFO flag, even though the signal handler will not be called
because the signal is blocked (a necessary step before using
sigwait-like calls).
This alternate mechanism may be particularly useful here because getting
the siginfo data out of the signal handler safely is a tricky business.
Although I haven't tried this, kqueue's SIGEV_SIGNAL may be helpful in
managing this from a single-threaded program. This is, however, not
portable.
--
Jilles Tjoelker
More information about the freebsd-hackers
mailing list