I've been doing this for a while but I'm just starting on daemon code and I thought signal handlers sounded like a good idea (it lets me close sockets and database handles, etc.) So I tried it, and got stuck right here...
I've read everything I can find on signal handlers, and this looks right to me:
sub GotSignal($) {
my $sig = shift;
print "Got a $sig signal, exiting\n";
exit(0);
}
# Install signal handlers
local $SIG{HUP} = 'IGNORE';
local $SIG{QUIT} = \&GotSignal('quit');
while (1) { # do stuff }
..But it doesn't work. As soon as the code hits the line where I assign a handler to $SIG{QUIT}, it runs that subroutine and exits. But if I do this:
# Install signal handlers
local $SIG{HUP} = 'IGNORE';
local $SIG{QUIT} = sub { my $sig = shift; print "Got a $sig sign
+al, exiting\n"; exit(0); };
while (1) { # do stuff }
The second example works as expected. This is on Linux (RH 6.2) runing perl5 (5.0 patchlevel 5 subversion 3). Anyone have any ideas? All help appreciated.
"Non sequitur. Your facts are un-coordinated." - Nomad
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.