in reply to Re: Why this daemon can only receive the HUP signal no more than one time?
in thread Why this daemon can only receive the HUP signal no more than one time?
Yes, indeed!
The daemon will blocked the SIGHUP signal when it execute the SIGHUP handler. And after it relaunch itself in the handler, the SIGHUP remains being blocked, so the SIGHUP sent later is pending.
Put the following code at the head of the scrpit:
my $emptySigSet = POSIX::SigSet->new(); my $oldSigSet = POSIX::SigSet->new(); POSIX::sigprocmask( &POSIX::SIG_BLOCK, $emptySigSet, $oldSigSet ); if ( $oldSigSet->ismember( &POSIX::SIGHUP ) ){ print "SIGHUP is blocking.\n"; }else { print "SIGHUP is not blocking.\n"; }
And replace the old hupMain with the following new one:
sub hupMain { while (1) { print "Running hup main function.\n"; sleep 3; my $pendingSigSet = POSIX::SigSet->new(); POSIX::sigpending( $pendingSigSet ) ; if ( $pendingSigSet->ismember( &POSIX::SIGHUP ) ){ print "Pending signal set contains SIG_HUP\n"; } } }
I can observe the SIGHUP signal is being blocking and pending.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Why this daemon can only receive the HUP signal no more than one time?
by lifeboat (Initiate) on Apr 05, 2017 at 09:34 UTC | |
by Anonymous Monk on Apr 05, 2017 at 17:38 UTC |