namespaces.7: ffix
[man-pages.git] / man2 / sigwaitinfo.2
blob00bc50485f5a0d171f489991bdb6febc2f5f131e
1 .\" Copyright (c) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH SIGWAITINFO 2 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 sigwaitinfo, sigtimedwait, rt_sigtimedwait \- synchronously wait
28 for queued signals
29 .SH SYNOPSIS
30 .nf
31 .B #include <signal.h>
32 .PP
33 .BI "int sigwaitinfo(const sigset_t *restrict " set ,
34 .BI "                siginfo_t *restrict " info );
35 .BI "int sigtimedwait(const sigset_t *restrict " set ,
36 .BI "                siginfo_t *restrict " info ,
37 .BI "                const struct timespec *restrict " timeout );
38 .fi
39 .PP
40 .RS -4
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
43 .RE
44 .PP
45 .BR sigwaitinfo (),
46 .BR sigtimedwait ():
47 .nf
48     _POSIX_C_SOURCE >= 199309L
49 .fi
50 .SH DESCRIPTION
51 .BR sigwaitinfo ()
52 suspends execution of the calling thread until one of the signals in
53 .I set
54 is pending
55 (If one of the signals in
56 .I set
57 is already pending for the calling thread,
58 .BR sigwaitinfo ()
59 will return immediately.)
60 .PP
61 .BR sigwaitinfo ()
62 removes the signal from the set of pending
63 signals and returns the signal number as its function result.
64 If the
65 .I info
66 argument is not NULL,
67 then the buffer that it points to is used to return a structure of type
68 .I siginfo_t
69 (see
70 .BR sigaction (2))
71 containing information about the signal.
72 .PP
73 If multiple signals in
74 .I set
75 are pending for the caller, the signal that is retrieved by
76 .BR sigwaitinfo ()
77 is determined according to the usual ordering rules; see
78 .BR signal (7)
79 for further details.
80 .PP
81 .BR sigtimedwait ()
82 operates in exactly the same way as
83 .BR sigwaitinfo ()
84 except that it has an additional argument,
85 .IR timeout ,
86 which specifies the interval for which
87 the thread is suspended waiting for a signal.
88 (This interval will be rounded up to the system clock granularity,
89 and kernel scheduling delays mean that the interval
90 may overrun by a small amount.)
91 This argument is of the following type:
92 .PP
93 .in +4n
94 .EX
95 struct timespec {
96     long    tv_sec;         /* seconds */
97     long    tv_nsec;        /* nanoseconds */
99 .EE
102 If both fields of this structure are specified as 0, a poll is performed:
103 .BR sigtimedwait ()
104 returns immediately, either with information about a signal that
105 was pending for the caller, or with an error
106 if none of the signals in
107 .I set
108 was pending.
109 .SH RETURN VALUE
110 On success, both
111 .BR sigwaitinfo ()
113 .BR sigtimedwait ()
114 return a signal number (i.e., a value greater than zero).
115 On failure both calls return \-1, with
116 .I errno
117 set to indicate the error.
118 .SH ERRORS
120 .B EAGAIN
121 No signal in
122 .I set
123 became pending within the
124 .I timeout
125 period specified to
126 .BR sigtimedwait ().
128 .B EINTR
129 The wait was interrupted by a signal handler; see
130 .BR signal (7).
131 (This handler was for a signal other than one of those in
132 .IR set .)
134 .B EINVAL
135 .I timeout
136 was invalid.
137 .SH CONFORMING TO
138 POSIX.1-2001, POSIX.1-2008.
139 .SH NOTES
140 In normal usage, the calling program blocks the signals in
141 .I set
142 via a prior call to
143 .BR sigprocmask (2)
144 (so that the default disposition for these signals does not occur if they
145 become pending between successive calls to
146 .BR sigwaitinfo ()
148 .BR sigtimedwait ())
149 and does not establish handlers for these signals.
150 In a multithreaded program,
151 the signal should be blocked in all threads, in order to prevent
152 the signal being treated according to its default disposition in
153 a thread other than the one calling
154 .BR sigwaitinfo ()
156 .BR sigtimedwait ()).
158 The set of signals that is pending for a given thread is the
159 union of the set of signals that is pending specifically for that thread
160 and the set of signals that is pending for the process as a whole (see
161 .BR signal (7)).
163 Attempts to wait for
164 .B SIGKILL
166 .B SIGSTOP
167 are silently ignored.
169 If multiple threads of a process are blocked
170 waiting for the same signal(s) in
171 .BR sigwaitinfo ()
173 .BR sigtimedwait (),
174 then exactly one of the threads will actually receive the
175 signal if it becomes pending for the process as a whole;
176 which of the threads receives the signal is indeterminate.
178 .BR sigwaitinfo ()
180 .BR sigtimedwait (),
181 can't be used to receive signals that
182 are synchronously generated, such as the
183 .BR SIGSEGV
184 signal that results from accessing an invalid memory address
185 or the
186 .BR SIGFPE
187 signal that results from an arithmetic error.
188 Such signals can be caught only via signal handler.
190 POSIX leaves the meaning of a NULL value for the
191 .I timeout
192 argument of
193 .BR sigtimedwait ()
194 unspecified, permitting the possibility that this has the same meaning
195 as a call to
196 .BR sigwaitinfo (),
197 and indeed this is what is done on Linux.
199 .SS C library/kernel differences
200 On Linux,
201 .BR sigwaitinfo ()
202 is a library function implemented on top of
203 .BR sigtimedwait ().
205 The glibc wrapper functions for
206 .BR sigwaitinfo ()
208 .BR sigtimedwait ()
209 silently ignore attempts to wait for the two real-time signals that
210 are used internally by the NPTL threading implementation.
212 .BR nptl (7)
213 for details.
215 The original Linux system call was named
216 .BR sigtimedwait ().
217 However, with the addition of real-time signals in Linux 2.2,
218 the fixed-size, 32-bit
219 .I sigset_t
220 type supported by that system call was no longer fit for purpose.
221 Consequently, a new system call,
222 .BR rt_sigtimedwait (),
223 was added to support an enlarged
224 .IR sigset_t
225 type.
226 The new system call takes a fourth argument,
227 .IR "size_t sigsetsize" ,
228 which specifies the size in bytes of the signal set in
229 .IR set .
230 This argument is currently required to have the value
231 .IR sizeof(sigset_t)
232 (or the error
233 .B EINVAL
234 results).
235 The glibc
236 .BR sigtimedwait ()
237 wrapper function hides these details from us, transparently calling
238 .BR rt_sigtimedwait ()
239 when the kernel provides it.
241 .SH SEE ALSO
242 .BR kill (2),
243 .BR sigaction (2),
244 .BR signal (2),
245 .BR signalfd (2),
246 .BR sigpending (2),
247 .BR sigprocmask (2),
248 .BR sigqueue (3),
249 .BR sigsetops (3),
250 .BR sigwait (3),
251 .BR signal (7),
252 .BR time (7)