From: Sanchit on
How can we know process id of process which is sending the signal??

Process A sends signal to process B. then how can we know process id
of A in B??
From: Jens Thoms Toerring on
Sanchit <sanchitgupta.1(a)gmail.com> wrote:
> How can we know process id of process which is sending the signal??

> Process A sends signal to process B. then how can we know process id
> of A in B??

If it's possible depends on your system. If the implementation
supports the XSI Extension option (this sounds more complicated
then it is, just read your man page for sigaction(2) and check
if the following is documented ;-) then you set the SA_SIGINFO
flag in the 'sa_flags' member of the 'sigaction' structure you
pass to sigaction() when installing the handler and then the
signal handler function will be called with three arguments
instead of just one:

void func( int signo, siginfo_t * info, void * context )

Now you can test what the structure of type 'siginfo_t' passed
to the signal handler this way tells you: if the value of its
'si_code' member is less than or equal to 0 (or compare it to
'SI_USER'), then the signal was generated by a process (i.e. by
kill(2) or raise(2) and is not due to e.g. a segmentation fault
etc.) and 'si_pid' member tells you the ID of the process that
send the signal.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt(a)toerring.de
\__________________________ http://toerring.de