01-23-06 07:55 AM
I came across this piece of code:
sigset_t mask, oldmask;
...
/* Set up the mask of signals to temporarily block. */
sigemptyset (&mask);
sigaddset (&mask, SIGUSR1);
...
/* Wait for a signal to arrive. */
sigprocmask (SIG_BLOCK, &mask, &oldmask);
while (!usr_interrupt)
sigsuspend (&oldmask);
sigprocmask (SIG_UNBLOCK, &mask, NULL);
The signal handler sets "usr_interrupt" on the occurance of SIGUSR1. My
doubt is that if sigprocmask is used to block SIGUSR1 then how is the
signal handler ever going to catch the SIGUSR1 signal in order to set
"usr_interrupt" so as to cause the while loop to transfer control to
the next statement?
I have seen a similar implementation in Steven's "Advanced Unix
Programming". I'd be grateful if you could kindly help me reason out
the logic to blocking the very signal which is supposed to trigger a
signal handler.
Thanks.
[ Post a follow-up to this message ]
|