Debian Codegraph @

upstream/debian-unstable/man2/sigwaitinfo.2

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