Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jun 2009 16:03:27 +0200
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Daniel Eischen <deischen@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, vasanth raonaik <vasanth.raonaik@gmail.com>
Subject:   Re: Regarding Signal IPC
Message-ID:  <20090619140326.GA75222@stack.nl>
In-Reply-To: <Pine.GSO.4.64.0906190859550.9039@sea.ntplx.net>
References:  <d9f479c10906190512x4d1cf271w4107bfee0404e52a@mail.gmail.com> <Pine.GSO.4.64.0906190859550.9039@sea.ntplx.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090619140326.GA75222>