Changes.old: tfix
[man-pages.git] / man2 / sigwaitinfo.2
blob5d302dfb54f60a78ed35b1fa1904b2712596a058
1 .\" Copyright (c) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH sigwaitinfo 2 (date) "Linux man-pages (unreleased)"
6 .SH NAME
7 sigwaitinfo, sigtimedwait, rt_sigtimedwait \- synchronously wait
8 for queued signals
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <signal.h>
16 .BI "int sigwaitinfo(const sigset_t *restrict " set ,
17 .BI "                siginfo_t *_Nullable restrict " info );
18 .BI "int sigtimedwait(const sigset_t *restrict " set ,
19 .BI "                siginfo_t *_Nullable restrict " info ,
20 .BI "                const struct timespec *restrict " timeout );
21 .fi
23 .RS -4
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
26 .RE
28 .BR sigwaitinfo (),
29 .BR sigtimedwait ():
30 .nf
31     _POSIX_C_SOURCE >= 199309L
32 .fi
33 .SH DESCRIPTION
34 .BR sigwaitinfo ()
35 suspends execution of the calling thread until one of the signals in
36 .I set
37 is pending
38 (If one of the signals in
39 .I set
40 is already pending for the calling thread,
41 .BR sigwaitinfo ()
42 will return immediately.)
44 .BR sigwaitinfo ()
45 removes the signal from the set of pending
46 signals and returns the signal number as its function result.
47 If the
48 .I info
49 argument is not NULL,
50 then the buffer that it points to is used to return a structure of type
51 .I siginfo_t
52 (see
53 .BR sigaction (2))
54 containing information about the signal.
56 If multiple signals in
57 .I set
58 are pending for the caller, the signal that is retrieved by
59 .BR sigwaitinfo ()
60 is determined according to the usual ordering rules; see
61 .BR signal (7)
62 for further details.
64 .BR sigtimedwait ()
65 operates in exactly the same way as
66 .BR sigwaitinfo ()
67 except that it has an additional argument,
68 .IR timeout ,
69 which specifies the interval for which
70 the thread is suspended waiting for a signal.
71 (This interval will be rounded up to the system clock granularity,
72 and kernel scheduling delays mean that the interval
73 may overrun by a small amount.)
74 This argument is a
75 .BR timespec (3)
76 structure.
78 If both fields of this structure are specified as 0, a poll is performed:
79 .BR sigtimedwait ()
80 returns immediately, either with information about a signal that
81 was pending for the caller, or with an error
82 if none of the signals in
83 .I set
84 was pending.
85 .SH RETURN VALUE
86 On success, both
87 .BR sigwaitinfo ()
88 and
89 .BR sigtimedwait ()
90 return a signal number (i.e., a value greater than zero).
91 On failure both calls return \-1, with
92 .I errno
93 set to indicate the error.
94 .SH ERRORS
95 .TP
96 .B EAGAIN
97 No signal in
98 .I set
99 became pending within the
100 .I timeout
101 period specified to
102 .BR sigtimedwait ().
104 .B EINTR
105 The wait was interrupted by a signal handler; see
106 .BR signal (7).
107 (This handler was for a signal other than one of those in
108 .IR set .)
110 .B EINVAL
111 .I timeout
112 was invalid.
113 .SH VERSIONS
114 .SS C library/kernel differences
115 On Linux,
116 .BR sigwaitinfo ()
117 is a library function implemented on top of
118 .BR sigtimedwait ().
120 The glibc wrapper functions for
121 .BR sigwaitinfo ()
123 .BR sigtimedwait ()
124 silently ignore attempts to wait for the two real-time signals that
125 are used internally by the NPTL threading implementation.
127 .BR nptl (7)
128 for details.
130 The original Linux system call was named
131 .BR sigtimedwait ().
132 However, with the addition of real-time signals in Linux 2.2,
133 the fixed-size, 32-bit
134 .I sigset_t
135 type supported by that system call was no longer fit for purpose.
136 Consequently, a new system call,
137 .BR rt_sigtimedwait (),
138 was added to support an enlarged
139 .I sigset_t
140 type.
141 The new system call takes a fourth argument,
142 .IR "size_t sigsetsize" ,
143 which specifies the size in bytes of the signal set in
144 .IR set .
145 This argument is currently required to have the value
146 .I sizeof(sigset_t)
147 (or the error
148 .B EINVAL
149 results).
150 The glibc
151 .BR sigtimedwait ()
152 wrapper function hides these details from us, transparently calling
153 .BR rt_sigtimedwait ()
154 when the kernel provides it.
156 .SH STANDARDS
157 POSIX.1-2008.
158 .SH HISTORY
159 POSIX.1-2001.
160 .SH NOTES
161 In normal usage, the calling program blocks the signals in
162 .I set
163 via a prior call to
164 .BR sigprocmask (2)
165 (so that the default disposition for these signals does not occur if they
166 become pending between successive calls to
167 .BR sigwaitinfo ()
169 .BR sigtimedwait ())
170 and does not establish handlers for these signals.
171 In a multithreaded program,
172 the signal should be blocked in all threads, in order to prevent
173 the signal being treated according to its default disposition in
174 a thread other than the one calling
175 .BR sigwaitinfo ()
177 .BR sigtimedwait ()).
179 The set of signals that is pending for a given thread is the
180 union of the set of signals that is pending specifically for that thread
181 and the set of signals that is pending for the process as a whole (see
182 .BR signal (7)).
184 Attempts to wait for
185 .B SIGKILL
187 .B SIGSTOP
188 are silently ignored.
190 If multiple threads of a process are blocked
191 waiting for the same signal(s) in
192 .BR sigwaitinfo ()
194 .BR sigtimedwait (),
195 then exactly one of the threads will actually receive the
196 signal if it becomes pending for the process as a whole;
197 which of the threads receives the signal is indeterminate.
199 .BR sigwaitinfo ()
201 .BR sigtimedwait (),
202 can't be used to receive signals that
203 are synchronously generated, such as the
204 .B SIGSEGV
205 signal that results from accessing an invalid memory address
206 or the
207 .B SIGFPE
208 signal that results from an arithmetic error.
209 Such signals can be caught only via signal handler.
211 POSIX leaves the meaning of a NULL value for the
212 .I timeout
213 argument of
214 .BR sigtimedwait ()
215 unspecified, permitting the possibility that this has the same meaning
216 as a call to
217 .BR sigwaitinfo (),
218 and indeed this is what is done on Linux.
219 .SH SEE ALSO
220 .BR kill (2),
221 .BR sigaction (2),
222 .BR signal (2),
223 .BR signalfd (2),
224 .BR sigpending (2),
225 .BR sigprocmask (2),
226 .BR sigqueue (3),
227 .BR sigsetops (3),
228 .BR sigwait (3),
229 .BR timespec (3),
230 .BR signal (7),
231 .BR time (7)