As ikegami points out, signals don't exist on win32, so what this is detailing is just an emulation. You can only use it from and between perl programs; and attempting to use it for anything other than 'Is the process still alive'; and 'kill process with extreme prejudice'; really doesn't work. #
I have a postit stuck on my wall that reads:
Win32 trappable sigs: BREAK/21, INT/2, QUIT/3, TERM/15; Others (except 0) always fatal!
Going by the faded color of the postit, it's probably at least 2 years old. I do remember it was frustratingly hard to verify this information. Anyone who wants to try might find this code useful as a starting point.
SigCheck.pl
#! perl -slw use strict; use Config; $|++; sub startKid { warn "starting kid\n"; my $pid = system 1, '/perl/bin/perl.exe trapSigs.pl' or die $!; sleep 0; warn "starting kid\n"; return $pid; } my $pid = startKid; for my $signo ( sort {$a<=>$b} split ' ', $Config{ sig_num } ) { warn "Skipping $signo\n\n" and next if $signo == 15 or $signo == 2 +1; warn "Trying $signo\n"; warn "kill $signo, $pid returned: ", kill( $signo, $pid ), "\n"; for( 1 .. 3 ) { my $rv = kill 0, $pid; print "Attempt $_ at kill 0, $pid returned: ", $rv; last unless $rv; sleep 1; } if( kill 0, $pid ) { warn "signal no: $signo was non-fatal\n\n"; } else { warn "signal no: $signo was fatal\n\n"; $pid = startKid; warn "Restarted kid: $pid\n"; sleep 1; } }
TrapSigs.pl
#! perl -slw use strict; use Config; print <>; close STDIN; my @sigs = split ' ', $Config{ sig_name }; shift @sigs; for ( @sigs ) { warn "Installing signal handler for $_\n"; eval qq[\$SIG{ $_ } = sub{ warn "Signal $_ received\n"; } ]; } my $count; while( 1 ) { $count += 1 for 1.. 1e6; warn $count; sleep 3; }
In reply to Re: Using Signals on Windows XP
by BrowserUk
in thread Using Signals on Windows XP
by PerlSearcher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |