sigtimedwait() — Wait for queued signals

Standards

Standards / Extensions C or C++ Dependencies

Single UNIX Specification, Version 2
Single UNIX Specification, Version 3

both

OS/390 V2R7

Format

#define _XOPEN_SOURCE 500
#include <signal.h>

int sigtimedwait(const sigset_t *set, siginfo_t *info
                 const struct timespec *timeout);

General description

The sigtimedwait() function selects a pending signal from the sigset_t object (signal set) pointed to by set, automatically clearing it from the system's set of pending signals, and returning that signal number. If there are multiple pending signals, the lowest numbered signal will be selected.

If no signal in the signal set is pending at the time of the call to sigtimedwait(), the thread is suspended until one or more of the signals specified in the signal set become pending or until it is interrupted by an unblocked, caught signal. The signals defined in the sigset_t object (signal set) pointed to by set may be unblocked during the call to this routine and will be blocked when the thread returns from the call unless some other thread is currently waiting for one of those signals.

If more than one thread is using sigtimedwait() to wait for the same signal, only one of these threads will return from this routine with the signal number, until a second signal of the same type is received.

The function sigtimedwait() behaves the same as the sigwait() function if the info argument is NULL. If the info argument is not NULL, then in addition to behaving the same as sigwait(), sigtimedwait() places the selected signal number in the si_signo member, places the cause of the signal in the si_code member, and, if any value is queued to the selected signal, sigtimedwait() will place it in the si_value member of info. However, if there is no value queued for the selected signal then the content of si_value is undefined.

If the sigtimedwait() function finds that none of the signals specified by set are pending, it waits for the time interval specified in the timespec structure referenced by timeout If the timespec structure pointed to by timeout is zero-valued and if none of the signals specified by set are pending, then sigtimedwait() returns immediately with an error. A timespec with the tv_sec field set with INT_MAX, as defined in <limits.h>, will cause the sigtimedwait() service to wait until a signal is received. If timeout is the NULL pointer, the behavior is not necessarily the same on all platforms but for this platform it will be treated the same as when timespec structure was supplied with with the tv_sec field set with INT_MAX.

Usage notes

The use of the SIGTHSTOP and SIGTHCONT signal is not supported with this function.

Returned value

If successful, sigtimedwait() returns the signal number.

If unsuccessful, sigtimedwait() returns -1 and sets errno to one of the following values:

Error Code
Description
EAGAIN
No signal specified by set was generated within the specified time out period.
EINTR
The wait was interrupted by an unblocked, caught signal. No further waiting will occur for this call. sigtimedwait() can be reissued to begin waiting again.
EINVAL
set points to a sigset_t that contains a signal number that is either not valid or not supported.

Related information