Hello,
If this is not the proper place for this question then my apologies
and please /kindly/ redirect me to the right place.
I am looking for a method to suspend the process and insure I do
not miss a signal that is supposed to wake the process back up.
The short amount of time between checking if a signal has fired
and suspending a process can be enough to miss a signal and forever
put the process to sleep. Typically, the process would be woken
by an alarm from a timer, but there are other signals that may
also fire from time to time.
My solution is the function shown below. It masks all signals,
checks a flag to see if a signal has been handled, then uses a
single function to unmask signals and suspend the process.
The unmasking that follows the sigsuspend function is used to
insure that signals are unmasked even if sigsuspend fails.
The flag value is normally zero and will have one or more bits
set if a signal has been handled. These are set in my signal handler.
This should work fine, but only if sigsuspend is prevents a signal
from being handled between the time it modifies the signal mask until
it suspends the process. The manual does not clearly state this one
way or the other. I am wondering if anyone can say with certainty that
this solution will or will not work.
Thanks in advance.
// ==================================================
void suspend( u_int flag )
{
sigset_t setallsignals, normal;
sigprocmask( SIG_BLOCK, &setallsignals, &normal );
if( !flag )
sigsuspend( &normal );
sigprocmask( SIG_SETMASK, &normal, NULL );
}