sigtimedwait and sigwaitinfo Subroutine

Purpose

Waits for a signal, and provides a mechanism for retrieving any queued value.

Library

Standard C Library (libc.a)

Threads Library (libpthreads.a)

Syntax

#include <signal.h>

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

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

Description

The sigwaitinfo subroutine selects a pending signal from the set specified by the set parameter. If no signal in the set parameter is pending at the time of the call, the calling thread is suspended until one or more signals in the set parameter become pending or until it is interrupted by an unblocked, caught signal. If the wait was interrupted by an unblocked, caught signal, the subroutines will restart themselves.

The sigwaitinfo subroutine is functionally equivalent to the sigwait subroutine if the info argument is NULL. If the info argument is non-NULL, the sigwaitinfo subroutine is equivalent to the sigwait subroutine, except that the selected signal number is stored in the si_signo member, and the cause of the signal is stored in the si_code member of the info parameter. If any value is queued to the selected signal, the first such queued value is dequeued, and if the info argument is non-NULL, the value is stored in the si_value member of the info parameter. If no further signals are queued for the selected signal, the pending indication for that signal is reset.

The sigtimedwait subroutine is equivalent to the sigwaitinfo subroutine except that if none of the signals specified by the set parameter are pending, the sigtimedwait subroutine waits for the time interval referenced by the timeout parameter. If the timespec structure pointed to by the timeout parameter contains a zero value and if none of the signals specified by the set parameter are pending, the sigtimedwait subroutine returns immediately with an error.

If there are multiple pending signals in the range SIGRTMIN to SIGRTMAX, the lowest numbered signal in that range will be selected.

Note: All signals in set should have been blocked prior to calling any of the sigwait subroutines.

Parameters

Item Description
set Specifies the pending signals that may be selected.
info Points to a siginfo_t in which additional signal information can be returned.
timeout Points to the timespec structure.

Return Values

Upon successful completion, the sigtimedwait and sigwaitinfo subroutines return the selected signal number. If unsuccessful, the sigtimedwait and sigwaitinfo subroutines return -1 and set the errno variable to indicate the error.

Error Codes

The sigtimedwait subroutine will fail if:
Item Description
EAGAIN No signal specified by the set parameter was generated within the specified timeout period.
The sigtimedwait and sigwaitinfo subroutines may fail if:
Item Description
EINVAL The set parameter is empty, or contains an invalid, non-catchable, or unsupported signal number.
The sigtimedwait subroutine may also fail when none of the selected signals are pending if:
Item Description
EINVAL The timeout parameter specified a tv_nsec value less than zero or greater than or equal to 1000 million.