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