Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Signal Handling throws Core Dump

by almut (Canon)
on Apr 25, 2007 at 16:20 UTC ( #612050=note: print w/replies, xml ) Need Help??


in reply to Signal Handling throws Core Dump

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) (...)

Replies are listed 'Best First'.
Re^2: Signal Handling throws Core Dump
by dsb (Chaplain) on Apr 25, 2007 at 16:43 UTC
    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 .... }
        Can you mention some of the WAY better ways or point at some references for them?
        I actually did take the "complicated" code out of the sig handler and put it into a couple of conditional blocks as you demonstrated. I did still get the core dumps. However, I can't remember if I left the handler as simple as incrementing the global $sig. I'll give that a go...


        dsb
        This @ISA my( $cool ) %SIG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://612050]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2022-01-24 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?