in reply to Signal Handler
The theory is described here, but in my experience this doesn't work as advertised...
For example, this is what I get on the Linux box (SuSE 10.2) I'm sending this from:
#!/usr/local/perl/5.10.0/bin/perl use strict; use warnings; use POSIX; use Data::Dumper; $Data::Dumper::Useqq = 1; my $inf; my $sender_pid; POSIX::sigaction( SIGINT, POSIX::SigAction->new( sub { $inf = Dumper \@_; $sender_pid = unpack "x16S", $_[2]; # <-- }, 0, POSIX::SA_SIGINFO ), ); kill 'INT', $$; print $inf; print "Sender PID: $sender_pid\n"; print "Own PID: $$\n"; __END__ $VAR1 = [ "INT", { "code" => 0, "signo" => 2 }, "\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0RQ\0\0005\4\0\0\270\273}\0\ +0\0\0\0`\257i\0\0\0\0\0\3342E\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 +\0\370\25e\0\0\0\0\0\30 e\0\0\0\0\0\1\0\0\0\0\0\0\0\r\0\0\0\0\0\0\0\3 +60b8\213\377\177\0\0\370b8\213\377\177\0\0\1\0\0\0\0\0\0\0\3IM\0\0\0\ +0\0" ]; Sender PID: 20818 (as we're sending the signal ourself, the sender i +s $$) Own PID: 20818
Ideally - as I'm reading the docs - there should also be hash fields for 'pid' (the process id generating the signal), 'uid', etc. — not available in this case, though.
With a bit of luck (and reading through your system's siginfo.h — (e.g. /usr/include/asm-generic/siginfo.h on my system)), you might be able to extract the relevant info from the raw siginfo struct dump...
Update: unpack "x16S", ... looks promising — at least in my case, it extracts the appropriate PID (see $sender_pid in the above updated snippet). But be sure to test its portability, before you make this a vital part of your application...! :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Signal Handler
by lakshmananindia (Chaplain) on Dec 06, 2008 at 03:53 UTC | |
by almut (Canon) on Dec 06, 2008 at 08:11 UTC | |
by lakshmananindia (Chaplain) on Dec 08, 2008 at 10:31 UTC |