sigwaitinfo()--Synchronously Accept a Signal and Signal Data


  Syntax
 #include <signal.h>

 int sigwaitinfo( const sigset_t *set,   
                  siginfo_t *info);

  Service Program Name: QPOSSRV1

  Default Public Authority: *USE

  Threadsafe: Yes


The sigwaitinfo() function selects a pending signal from set, clears it from the set of pending signals for the thread or process, and returns that signal number in the si_signo member in the structure that is referenced by info. If prior to the call to sigwaitinfo() there are multiple pending instances of a single signal number, upon successful return the number of remaining signals for that signal number is decremented by one.

If no signal in set is pending at the time of the call, the thread shall be suspended. The thread does not resume until one or more signals in set become pending.

The signals defined by set are required to be blocked at the time of the call to sigwaitinfo(); otherwise, sigwaitinfo() is not successful, and an [EINVAL] error is returned. The signals SIGKILL or SIGStop cannot be selected. Any attempt to use sigwaitinfo() to select these signals is simply ignored, and no error is returned.

The signal action for the signal in set that is returned in the member si_signo in the structure referenced by info is not taken.

If more than one thread is using a sigwait function to wait for the same signal, only one of these threads will return from the sigwait function with the signal number. If more than one thread is waiting for the same signal, the first thread to wait on the signal will return from the sigwait function.


Authorities and Locks

None.


Parameters

*set
(Input) A pointer to a signal set to be waited upon.

*info
(Output) A pointer to the storage location where sigwaitinfo() can store the signal related information for the signal number that completed the wait. This value may be NULL. The siginfo_t structure is described in sigaction()--Examine and Change Signal Action.

Return Value

0 sigwaitinfo() was successful.
-1 sigwaitinfo() was not successful. The errno variable is set to indicate the reason.


Error Conditions

If sigwaitinfo() is not successful, errno usually indicates the following error. Under some conditions, errno could indicate an error other than that listed here.

[EINVAL]

The value specified for the argument is not correct.

A function was passed incorrect argument values, or an operation was attempted on an object and the operation specified is not supported for that type of object.

An argument value is not valid, out of range, or NULL.

One of the following has occurred:



[ENOTSIGINIT]

Process not enabled for signals.

An attempt was made to call a signal function under one of the following conditions:


Usage Notes

The sigwaitinfo() 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, sigwaitinfo() is not successful, and an [ENOTSIGINIT] error is returned.


Related Information


Example

The following example suspends processing by using the sigwaitinfo() function and determines the current time.

The signal catching function is not called.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>

extern int errno;

void catcher( int sig ) {
    printf( "Signal catcher called for signal %d\n", sig );
}

void timestamp( char *str ) {
    time_t t;

    time( T );
    printf( "The time %s is %s\n", str, ctime(T) );
}

int main( int argc, char *argv[] ) {

    int result = 0;

    struct sigaction sigact;
    sigset_t waitset;
    siginfo_t info;

    sigemptyset( &sigact.sa_mask );
    sigact.sa_flags = 0;
    sigact.sa_handler = catcher;
    sigaction( SIGALRM, &sigact, NULL );

    sigemptyset( &waitset );
    sigaddset( &waitset, SIGALRM );

    sigprocmask( SIG_BLOCK, &waitset, NULL );

    alarm( 10 );

    timestamp( "before sigwaitinfo(" );

    result = sigwaitinfo( &waitset, &info );

    if( result == 0 )
        printf( "sigwaitinfo() returned for signal %d\n",
                 info.si_signo );
    else {
        printf( "sigwait() returned error number %d\n", errno );
        perror( "sigwait() function failed\n" );
    }

    timestamp( "after sigwaitinfo()" );

    return( result );
}

Output:

    The time before sigwaitinfo() is Tue Jul 15 11:22:56 1997
    sigwaitinfo() returned for signal 14
    The time after sigwaitinfo() is Tue Jul 15 11:23:07 1997


API introduced: V4R2

[ Back to top | UNIX-Type APIs | APIs by category ]