Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Signal Handling throws Core Dump

by dsb (Chaplain)
on Apr 25, 2007 at 14:03 UTC ( #612021=perlquestion: print w/ replies, xml ) Need Help??
dsb has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to catch SIG_INTs in the usual way:
$SIG{INT} = \&handler; sub handler { $sig++; }
Trouble is, it seems that everytime a signal is sent/caught, the process core dumps. I've read the bit in perlipc that talks about safe and unsafe signals and although I was initially running slightly more complicated code in the handler() routine, it is now as simple as is demonstrated here but still core dumping.

I have no more ideas and could use some help.

Update:
Thanks Paul. I'm on Solaris 10, using Perl 5.8.8.

Thanks


dsb
This @ISA my( $cool ) %SIG

Comment on Signal Handling throws Core Dump
Download Code
Re: Signal Handling throws Core Dump
by jettero (Monsignor) on Apr 25, 2007 at 14:06 UTC

    It would be helpful to know what unstable platform you're on or what unstable build of perl you're using.

    Update: wow, then that shouldn't be happening imo; but, I have no further information on why. Is it the sun build of perl 5.8.8? What is $sig? Signals are kinda strange monsters (or can be depending on the implementation) and I can't help but wonder if $sig is getting deallocated lexically and then cleaned up again during global destruction or something vile like that.

    -Paul

      $sig is just a scalar I use to determine when the loop should stop.
      until ($sig) { # do some stuff }
      I declare $sig earlier with our in attempt to disqualify any scoping issues as the source of problems. I'm going to try it on another box with the same set up and see if I have the same issue.

      Update:
      I tried it on a different server running the same OS and version Perl, with the same result.


      dsb
      This @ISA my( $cool ) %SIG
      in case of lexical $sig that code would create closure, so no deallocation could take place.
Re: Signal Handling throws Core Dump
by cengineer (Pilgrim) on Apr 25, 2007 at 15:29 UTC
    Not sure if it's a Solaris specific thing, but I used this on Linux with perl 5.8.8 and it works fine:

    use sigtrap qw(handler sig_handler INT TERM QUIT PIPE); use Switch; sub sig_handler { my($sig) = shift; print "Caught signal $sig\n"; switch($sig) { case ["INT","TERM","QUIT"] { print "Exiting"; exit(0); } case "PIPE" { print "Continuing\n"; } } }
      Used this method but get the same result. It seems like as soon as I try to do anything that I get the core dump.


      dsb
      This @ISA my( $cool ) %SIG
Re: Signal Handling throws Core Dump
by almut (Canon) on Apr 25, 2007 at 16:20 UTC

    Not sure if this is of any help (because on the Solaris 10 box I have within reach, there's only an older Perl installed), but just in case: the following works fine here

    #!/usr/bin/perl our $sig; # same for my $sig $SIG{INT} = \&handler; sub handler { print "got SIGINT\n"; $sig++; } until ($sig) { print "running...\n"; sleep 1; } print "terminated.\n";

    outputs as expected (until/when I send it SIGINT)

    running... running... running... got SIGINT terminated.

    Can you produce a backtrace, loading your core file in a debugger (gdb perl core, then, at the prompt, typing "bt" — in case you have gdb available, that is...)? This might give a first hint at where things are going wrong. (A perl binary built with debugging info would be better, of course...)

    ___

    $ uname -a SunOS solaris10 5.10 Generic sun4u sparc SUNW,Sun-Blade-2500 $ perl -v This is perl, v5.8.4 built for sun4-solaris-64int (with 27 registered patches, see perl -V for more detail) (...)
      When I give $SIG{INT} an anonymous subroutine, I can at least get it it to increment $sig and exit cleanly.

      But when I try to run an object method designed to remove a stored PID from a DB, it cores.

      # doesn't work $SIG{INT} = sub { $sig++; $control->removeMonitorPID($monitor->{PID}); };


      dsb
      This @ISA my( $cool ) %SIG
        Well, that shouldn't be too surprising. You're not really supposed to do stuff like that from a signal handler. That's not even a perl specific issue.

        -Paul

        I first want to clarify that there are WAY better ways to do this, but if you want to increment a global variable to detect a signal being caught this will do the trick. As Paul noted earlier you shouldn't be trying to do anything complicated in the signal handler itself.
        our $sig; $sig = 1; $SIG{INT} = sub { $sig++; }; my $oldsig; while (1) { if ($sig != $oldsig) { $control->removeMonitorPID($monitor->{PID}); #Execute the code ori +ginally in the signal handler. $oldsig = $sig; } .... Run main loop, but make sure to poll the status of the global v +ariable .... }
Re: Signal Handling throws Core Dump
by Steve_p (Priest) on Apr 26, 2007 at 17:19 UTC

    I've tried a couple of the scripts above with Solaris Express and the supplied Perl 5.8.4 and bleadperl. I've not seen any core dumps with either. I do have some more questions, but they would best be answered by you pasting in the output from perl -V into a reply.



    Test your modules with bleadperl!

      rsync -avz rsync://public.activestate.com/perl-current/ .
      ./Configure -des -Dusedevel -Dprefix=/path/to/test/perl
      make test
      make install
    

    Now, please test you modules! If you have test failures that don't happen with Perl 5.8.8, send a simplified test case to

    perlbug at perl.org

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-09-16 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (53 votes), past polls