]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/epoll_wait.2
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man2 / epoll_wait.2
1 .\" Copyright (C) 2003 Davide Libenzi
2 .\" Davide Libenzi <davidel@xmailserver.org>
3 .\" and Copyright 2007, 2012, 2014, 2018 Michael Kerrisk <tk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\"
7 .\" 2007-04-30: mtk, Added description of epoll_pwait()
8 .\"
9 .TH EPOLL_WAIT 2 2021-03-22 "Linux man-pages (unreleased)"
10 .SH NAME
11 epoll_wait, epoll_pwait, epoll_pwait2 \-
12 wait for an I/O event on an epoll file descriptor
13 .SH LIBRARY
14 Standard C library
15 .RI ( libc ", " \-lc )
16 .SH SYNOPSIS
17 .nf
18 .B #include <sys/epoll.h>
19 .PP
20 .BI "int epoll_wait(int " epfd ", struct epoll_event *" events ,
21 .BI " int " maxevents ", int " timeout );
22 .BI "int epoll_pwait(int " epfd ", struct epoll_event *" events ,
23 .BI " int " maxevents ", int " timeout ,
24 .BI " const sigset_t *" sigmask );
25 .BI "int epoll_pwait2(int " epfd ", struct epoll_event *" events ,
26 .BI " int " maxevents ", const struct timespec *" timeout ,
27 .BI " const sigset_t *" sigmask );
28 .fi
29 .SH DESCRIPTION
30 The
31 .BR epoll_wait ()
32 system call waits for events on the
33 .BR epoll (7)
34 instance referred to by the file descriptor
35 .IR epfd .
36 The buffer pointed to by
37 .I events
38 is used to return information from the ready list
39 about file descriptors in the interest list that
40 have some events available.
41 Up to
42 .I maxevents
43 are returned by
44 .BR epoll_wait ().
45 The
46 .I maxevents
47 argument must be greater than zero.
48 .PP
49 The
50 .I timeout
51 argument specifies the number of milliseconds that
52 .BR epoll_wait ()
53 will block.
54 Time is measured against the
55 .B CLOCK_MONOTONIC
56 clock.
57 .PP
58 A call to
59 .BR epoll_wait ()
60 will block until either:
61 .IP \(bu 2
62 a file descriptor delivers an event;
63 .IP \(bu
64 the call is interrupted by a signal handler; or
65 .IP \(bu
66 the timeout expires.
67 .PP
68 Note that the
69 .I timeout
70 interval will be rounded up to the system clock granularity,
71 and kernel scheduling delays mean that the blocking interval
72 may overrun by a small amount.
73 Specifying a
74 .I timeout
75 of \-1 causes
76 .BR epoll_wait ()
77 to block indefinitely, while specifying a
78 .I timeout
79 equal to zero cause
80 .BR epoll_wait ()
81 to return immediately, even if no events are available.
82 .PP
83 The
84 .I struct epoll_event
85 is described in
86 .BR epoll_event (3type).
87 .PP
88 The
89 .I data
90 field of each returned
91 .I epoll_event
92 structure contains the same data as was specified
93 in the most recent call to
94 .BR epoll_ctl (2)
95 .RB ( EPOLL_CTL_ADD ", " EPOLL_CTL_MOD )
96 for the corresponding open file descriptor.
97 .PP
98 The
99 .I events
100 field is a bit mask that indicates the events that have occurred for the
101 corresponding open file description.
102 See
103 .BR epoll_ctl (2)
104 for a list of the bits that may appear in this mask.
105 .\"
106 .SS epoll_pwait()
107 The relationship between
108 .BR epoll_wait ()
109 and
110 .BR epoll_pwait ()
111 is analogous to the relationship between
112 .BR select (2)
113 and
114 .BR pselect (2):
115 like
116 .BR pselect (2),
117 .BR epoll_pwait ()
118 allows an application to safely wait until either a file descriptor
119 becomes ready or until a signal is caught.
120 .PP
121 The following
122 .BR epoll_pwait ()
123 call:
124 .PP
125 .in +4n
126 .EX
127 ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
128 .EE
129 .in
130 .PP
131 is equivalent to
132 .I atomically
133 executing the following calls:
134 .PP
135 .in +4n
136 .EX
137 sigset_t origmask;
138
139 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
140 ready = epoll_wait(epfd, &events, maxevents, timeout);
141 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
142 .EE
143 .in
144 .PP
145 The
146 .I sigmask
147 argument may be specified as NULL, in which case
148 .BR epoll_pwait ()
149 is equivalent to
150 .BR epoll_wait ().
151 .\"
152 .SS epoll_pwait2()
153 The
154 .BR epoll_pwait2 ()
155 system call is equivalent to
156 .BR epoll_pwait ()
157 except for the
158 .I timeout
159 argument.
160 It takes an argument of type
161 .I timespec
162 to be able to specify nanosecond resolution timeout.
163 This argument functions the same as in
164 .BR pselect (2)
165 and
166 .BR ppoll (2).
167 If
168 .I timeout
169 is NULL, then
170 .BR epoll_pwait2 ()
171 can block indefinitely.
172 .SH RETURN VALUE
173 On success,
174 .BR epoll_wait ()
175 returns the number of file descriptors ready for the requested I/O, or zero
176 if no file descriptor became ready during the requested
177 .I timeout
178 milliseconds.
179 On failure,
180 .BR epoll_wait ()
181 returns \-1 and
182 .I errno
183 is set to indicate the error.
184 .SH ERRORS
185 .TP
186 .B EBADF
187 .I epfd
188 is not a valid file descriptor.
189 .TP
190 .B EFAULT
191 The memory area pointed to by
192 .I events
193 is not accessible with write permissions.
194 .TP
195 .B EINTR
196 The call was interrupted by a signal handler before either (1) any of the
197 requested events occurred or (2) the
198 .I timeout
199 expired; see
200 .BR signal (7).
201 .TP
202 .B EINVAL
203 .I epfd
204 is not an
205 .B epoll
206 file descriptor, or
207 .I maxevents
208 is less than or equal to zero.
209 .SH VERSIONS
210 .BR epoll_wait ()
211 was added to the kernel in version 2.6.
212 .\" To be precise: kernel 2.5.44.
213 .\" The interface should be finalized by Linux kernel 2.5.66.
214 Library support is provided in glibc starting with version 2.3.2.
215 .PP
216 .BR epoll_pwait ()
217 was added to Linux in kernel 2.6.19.
218 Library support is provided in glibc starting with version 2.6.
219 .PP
220 .BR epoll_pwait2 ()
221 was added to Linux in kernel 5.11.
222 .SH STANDARDS
223 .BR epoll_wait (),
224 .BR epoll_pwait (),
225 and
226 .BR epoll_pwait2 ()
227 are Linux-specific.
228 .SH NOTES
229 While one thread is blocked in a call to
230 .BR epoll_wait (),
231 it is possible for another thread to add a file descriptor to the waited-upon
232 .B epoll
233 instance.
234 If the new file descriptor becomes ready,
235 it will cause the
236 .BR epoll_wait ()
237 call to unblock.
238 .PP
239 If more than
240 .I maxevents
241 file descriptors are ready when
242 .BR epoll_wait ()
243 is called, then successive
244 .BR epoll_wait ()
245 calls will round robin through the set of ready file descriptors.
246 This behavior helps avoid starvation scenarios,
247 where a process fails to notice that additional file descriptors
248 are ready because it focuses on a set of file descriptors that
249 are already known to be ready.
250 .PP
251 Note that it is possible to call
252 .BR epoll_wait ()
253 on an
254 .B epoll
255 instance whose interest list is currently empty
256 (or whose interest list becomes empty because file descriptors are closed
257 or removed from the interest in another thread).
258 The call will block until some file descriptor is later added to the
259 interest list (in another thread) and that file descriptor becomes ready.
260 .SS C library/kernel differences
261 The raw
262 .BR epoll_pwait ()
263 and
264 .BR epoll_pwait2 ()
265 system calls have a sixth argument,
266 .IR "size_t sigsetsize" ,
267 which specifies the size in bytes of the
268 .I sigmask
269 argument.
270 The glibc
271 .BR epoll_pwait ()
272 wrapper function specifies this argument as a fixed value
273 (equal to
274 .IR sizeof(sigset_t) ).
275 .SH BUGS
276 In kernels before 2.6.37, a
277 .I timeout
278 value larger than approximately
279 .I LONG_MAX / HZ
280 milliseconds is treated as \-1 (i.e., infinity).
281 Thus, for example, on a system where
282 .I sizeof(long)
283 is 4 and the kernel
284 .I HZ
285 value is 1000,
286 this means that timeouts greater than 35.79 minutes are treated as infinity.
287 .SH SEE ALSO
288 .BR epoll_create (2),
289 .BR epoll_ctl (2),
290 .BR epoll (7)