Question on handling SIGALRM.
Tue, 6 May 97 17:21:12 IST


I have a problem with handling of the SIGALRM signal.

Following is the problem scenario :

action.sa_handler = myhandler;
sigaction(SIGALRM, &action, 0);
/* Normal processing */
/* Start of critical section */
sigaddset(&set, SIGALRM);
sigprocmask(SIG_BLOCK, &set, 0);
/* Want to reset the alarm to a new value */
sigprocmask(SIG_UNBLOCK, &set, 0);
/* End of critical section */

When the new alarm() is set in the critical section, the signal
could already have been raised or not due to the previous invocation
of alarm(). If it is not raised then there's no problem, but
if its already raised and blocking, then I would not like the handler
to be called, because the handler's functionality is no longer
required for previous value of alarm(). For this we need to
check in the critical section if the signal is already pending and
if so, then somehow ignore its effect. Is there a way to reset the
SIGALRM signal after it is raised and blocked.

But if the signal has been raised due to setting of the new alarm()
value then the handler should be called. Is there a way to find this

Should not alarm() reset any pending SIGALRM, because that is what the
user wants (most of the time...). Or otherwise should it have a flag
to set such behaviour ?


Sameer Shah,
IIT- Kanpur 208 016, India                 

PS: Is there a simple way to reset any pending signal ?