Syntax #include <signal.h> int sigsuspend( const sigset_t *sigmask );
|
The sigsuspend() function replaces the current signal mask of a thread with the signal set given by *sigmask and then suspends processing of the calling process. The thread does not resume running until a signal is delivered whose action is to call a signal-catching function, to end the request, or to terminate the process. (Signal sets are described in more detail in sigemptyset()--Initialize and Empty Signal Set.)
The signal mask indicates a set of signals that should be blocked. Such signals do not "wake up" the suspended function. The signals SIGSTOP and SIGKILL cannot be blocked or ignored; they are delivered to the thread regardless of what the sigmask argument specifies.
If an incoming unblocked signal has an action of end the request of terminate the process, sigsuspend() never returns to the caller. If an incoming signal is handled by a signal-catching function, sigsuspend() returns after the signal-catching function returns. In this case, the signal mask of the thread is restored to whatever it was before sigsuspend() was called.
Parameters
Return Value
There is no return value to indicate successful completion.
Error Conditions
If sigsuspend() returns, errno indicates the following:
A signal was received and handled by a signal-catching function that returned.
A parameter passed to this function is not valid.
The signal set pointed to by sigmask contains a signal that is not within the valid range or a signal that is not supported.
An attempt was made to call a signal function under one of the following conditions:
The current thread state would prevent the signal function from completing.
Usage Notes
The sigsuspend function enables a process for signals if the process is not already enabled for signals. For details, see Qp0sEnableSignals()--Enable Process for Signals. If the system has not been enabled for signals, sigsuspend() is not successful, and an [ENOTSIGINIT] error is returned.
Related Information
Example
The following example replaces the signal mask and then suspends processing:
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
void catcher( int sig ) {
printf( "inside catcher() function\n" );
}
void timestamp( char *str ) {
time_t t;
time( &t );
printf( "%s the time is %s\n", str, ctime(&t) );
}
int main( int argc, char *argv[] ) {
struct sigaction sigact;
sigset_t block_set;
sigfillset( &block_set );
sigdelset( &block_set, SIGALRM );
sigemptyset( &sigact.sa_mask );
sigact.sa_flags = 0;
sigact.sa_handler = catcher;
sigaction( SIGALRM, &sigact, NULL );
timestamp( "before sigsuspend()" );
alarm( 10 );
sigsuspend( &block_set );
timestamp( "after sigsuspend()" );
return( 0 );
}
Output:
before sigsuspend() the time is Sun Jan 22 17:11:41 1995
inside catcher() function
after sigsuspend() the time is Sun Jan 22 17:11:51 1995
|
Top
| Signal APIs
| UNIX-Type APIs APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |