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; }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Using Signals on Windows XP by BrowserUk
in thread Using Signals on Windows XP by PerlSearcher

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.