man-pages/man2/sigwaitinfo.2.html
2021-03-31 01:06:50 +01:00

380 lines
8.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SIGWAITINFO</TITLE>
</HEAD><BODY>
<H1>SIGWAITINFO</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
sigwaitinfo, sigtimedwait, rt_sigtimedwait - synchronously wait
for queued signals
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/signal.h">signal.h</A>&gt;</B>
<B>int sigwaitinfo(const sigset_t *</B><I>set</I><B>, siginfo_t *</B><I>info</I><B>);</B>
<B>int sigtimedwait(const sigset_t *</B><I>set</I><B>, siginfo_t *</B><I>info</I><B>, </B>
<B> const struct timespec *</B><I>timeout</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>sigwaitinfo</B>(),
<B>sigtimedwait</B>():
_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;199309L
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>sigwaitinfo</B>()
suspends execution of the calling thread until one of the signals in
<I>set</I>
is pending
(If one of the signals in
<I>set</I>
is already pending for the calling thread,
<B>sigwaitinfo</B>()
will return immediately.)
<P>
<B>sigwaitinfo</B>()
removes the signal from the set of pending
signals and returns the signal number as its function result.
If the
<I>info</I>
argument is not NULL,
then the buffer that it points to is used to return a structure of type
<I>siginfo_t</I>
(see
<B><A HREF="/cgi-bin/man/man2html?2+sigaction">sigaction</A></B>(2))
containing information about the signal.
<P>
If multiple signals in
<I>set</I>
are pending for the caller, the signal that is retrieved by
<B>sigwaitinfo</B>()
is determined according to the usual ordering rules; see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7)
for further details.
<P>
<B>sigtimedwait</B>()
operates in exactly the same way as
<B>sigwaitinfo</B>()
except that it has an additional argument,
<I>timeout</I>,
which specifies the interval for which
the thread is suspended waiting for a signal.
(This interval will be rounded up to the system clock granularity,
and kernel scheduling delays mean that the interval
may overrun by a small amount.)
This argument is of the following type:
<P>
struct timespec {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;&nbsp;&nbsp;tv_sec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;seconds&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;&nbsp;&nbsp;tv_nsec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;nanoseconds&nbsp;*/
}
<P>
If both fields of this structure are specified as 0, a poll is performed:
<B>sigtimedwait</B>()
returns immediately, either with information about a signal that
was pending for the caller, or with an error
if none of the signals in
<I>set</I>
was pending.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, both
<B>sigwaitinfo</B>()
and
<B>sigtimedwait</B>()
return a signal number (i.e., a value greater than zero).
On failure both calls return -1, with
<I>errno</I>
set to indicate the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EAGAIN</B>
<DD>
No signal in
<I>set</I>
was became pending within the
<I>timeout</I>
period specified to
<B>sigtimedwait</B>().
<DT id="2"><B>EINTR</B>
<DD>
The wait was interrupted by a signal handler; see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
(This handler was for a signal other than one of those in
<I>set</I>.)
<DT id="3"><B>EINVAL</B>
<DD>
<I>timeout</I>
was invalid.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
In normal usage, the calling program blocks the signals in
<I>set</I>
via a prior call to
<B><A HREF="/cgi-bin/man/man2html?2+sigprocmask">sigprocmask</A></B>(2)
(so that the default disposition for these signals does not occur if they
become pending between successive calls to
<B>sigwaitinfo</B>()
or
<B>sigtimedwait</B>())
and does not establish handlers for these signals.
In a multithreaded program,
the signal should be blocked in all threads, in order to prevent
the signal being treated according to its default disposition in
a thread other than the one calling
<B>sigwaitinfo</B>()
or
<B>sigtimedwait</B>()).
<P>
The set of signals that is pending for a given thread is the
union of the set of signals that is pending specifically for that thread
and the set of signals that is pending for the process as a whole (see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7)).
<P>
Attempts to wait for
<B>SIGKILL</B>
and
<B>SIGSTOP</B>
are silently ignored.
<P>
If multiple threads of a process are blocked
waiting for the same signal(s) in
<B>sigwaitinfo</B>()
or
<B>sigtimedwait</B>(),
then exactly one of the threads will actually receive the
signal if it becomes pending for the process as a whole;
which of the threads receives the signal is indeterminate.
<P>
<B>sigwaitinfo</B>()
or
<B>sigtimedwait</B>(),
can't be used to receive signals that
are synchronously generated, such as the
<B>SIGSEGV</B>
signal that results from accessing an invalid memory address
or the
<B>SIGFPE</B>
signal that results from an arithmetic error.
Such signals can be caught only via signal handler.
<P>
POSIX leaves the meaning of a NULL value for the
<I>timeout</I>
argument of
<B>sigtimedwait</B>()
unspecified, permitting the possibility that this has the same meaning
as a call to
<B>sigwaitinfo</B>(),
and indeed this is what is done on Linux.
<A NAME="lbAI">&nbsp;</A>
<H3>C library/kernel differences</H3>
On Linux,
<B>sigwaitinfo</B>()
is a library function implemented on top of
<B>sigtimedwait</B>().
<P>
The glibc wrapper functions for
<B>sigwaitinfo</B>()
and
<B>sigtimedwait</B>()
silently ignore attempts to wait for the two real-time signals that
are used internally by the NPTL threading implementation.
See
<B><A HREF="/cgi-bin/man/man2html?7+nptl">nptl</A></B>(7)
for details.
<P>
The original Linux system call was named
<B>sigtimedwait</B>().
However, with the addition of real-time signals in Linux 2.2,
the fixed-size, 32-bit
<I>sigset_t</I>
type supported by that system call was no longer fit for purpose.
Consequently, a new system call,
<B>rt_sigtimedwait</B>(),
was added to support an enlarged
<I>sigset_t</I>
type.
The new system call takes a fourth argument,
<I>size_t sigsetsize</I>,
which specifies the size in bytes of the signal set in
<I>set</I>.
This argument is currently required to have the value
<I>sizeof(sigset_t)</I>
(or the error
<B>EINVAL</B>
results).
The glibc
<B>sigtimedwait</B>()
wrapper function hides these details from us, transparently calling
<B>rt_sigtimedwait</B>()
when the kernel provides it.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+kill">kill</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+sigaction">sigaction</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+signal">signal</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+signalfd">signalfd</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+sigpending">sigpending</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+sigprocmask">sigprocmask</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+sigqueue">sigqueue</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sigsetops">sigsetops</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sigwait">sigwait</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+time">time</A></B>(7)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="9"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="10"><A HREF="#lbAH">NOTES</A><DD>
<DL>
<DT id="11"><A HREF="#lbAI">C library/kernel differences</A><DD>
</DL>
<DT id="12"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="13"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:34 GMT, March 31, 2021
</BODY>
</HTML>