Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Signal Handling throws Core Dump

by dsb (Chaplain)
on Apr 25, 2007 at 16:43 UTC ( #612055=note: print w/ replies, xml ) Need Help??


in reply to Re: Signal Handling throws Core Dump
in thread Signal Handling throws Core Dump

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


Comment on Re^2: Signal Handling throws Core Dump
Download Code
Replies are listed 'Best First'.
Re^3: Signal Handling throws Core Dump
by jettero (Monsignor) on Apr 25, 2007 at 16:57 UTC
    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

Re^3: Signal Handling throws Core Dump
by former33t (Scribe) on Apr 26, 2007 at 03:05 UTC
    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
Node Status?
node history
Node Type: note [id://612055]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2015-07-29 02:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls