Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

sending signal to self with kill on windows

by bulk88 (Priest)
on Dec 30, 2012 at 05:29 UTC ( #1010891=perlquestion: print w/ replies, xml ) Need Help??
bulk88 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to send a signal from a Perl process to the same Perl process on Windows to run one of the %SIG handlers. So far I have
use warnings; use strict; use Config; use Data::Dumper; my (%signo, @signame, $i); $i = 0; defined $Config{sig_name} || die "No sigs?"; foreach my $name (split(' ', $Config{sig_name})) { $signo{$name} = $i; $signame[$i] = $name; $i++; } print Dumper(\@signame); sub sighandler { print "sighandler called\n"; } $SIG{BREAK} = \&sighandler; sub s1 { kill("BREAK", $$); } s1(); sleep 1; print "after sleep\n"; exit;
The output I got was
$VAR1 = [ "ZERO", "HUP", "INT", "QUIT", "ILL", "NUM05", "NUM06", "NUM07", "FPE", "KILL", "NUM10", "SEGV", "NUM12", "PIPE", "ALRM", "TERM", "NUM16", "NUM17", "NUM18", "NUM19", "CHLD", "BREAK", "ABRT", "STOP", "NUM24", "CONT", "CLD" ]; after sleep
Why wasn't the %SIG handler called?

edit: remove wrong wording, tip from browseruk

Comment on sending signal to self with kill on windows
Select or Download Code
Re: sending signal to self with kill on windows (updated);
by BrowserUk (Pope) on Dec 30, 2012 at 05:54 UTC
    Why wasn't the %INC handler called?

    What the heck is an " %INC handler"?

    Update: assuming you mean %SIG handler; I think this demonstrates that the Perl Windows sig emulation has code to prevent a process from attempting to signal itself:

    C:\test>start /b perl -E"say $$; sleep 10000" C:\test>192904 C:\test>perl -E"kill 21, 192904 or die $^E" Terminating on signal SIGBREAK(21) C:\test>perl -E"kill 21, $$ or say $^E; say 'ending';" The parameter is incorrect ending

    It doesn't make a great deal of sense to signal yourself to invoke a subroutine when you can just:

    C:\test>perl -wE"$SIG{BREAK}=sub{ say 'BREAKing' }; &{$SIG{BREAK}}; sa +y 'ending'; " BREAKing ending

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.
      > I think this demonstrates that the Perl Windows sig emulation has code to prevent a process from attempting to signal itself:

      Definitely! I had this at one of my projects...

      My face and all my hairs went pale, when I realized that a young colleague of mine called warn within $SIG{__WARN__}-handler.

      As it turned out Perl was (since 5.8 IIRC) idiot proof. It locally resets signal handler redirections before calling them.

      My colleague insisted that I exaggerated, because she "tested" (i.e ran) it once before committing into production.

      Her warn did depend on an if clause and "production" meant a central module of a mod-perl environment...

      Cheers Rolf

      UPDATE:

      from warn

      Most handlers must therefore make arrangements to actually display the warnings that they are not prepare +d to deal with, by calling "warn" again in the handler. Not +e that this is quite safe and will not produce an endless loop +, since "__WARN__" hooks are not called from inside one.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1010891]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-08-21 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (143 votes), past polls