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>
5 .\" %%%LICENSE_START(GPLv2+_SW_3_PARA)
6 .\" This program is free software; you can redistribute it and/or modify
7 .\" it under the terms of the GNU General Public License as published by
8 .\" the Free Software Foundation; either version 2 of the License, or
9 .\" (at your option) any later version.
11 .\" This program is distributed in the hope that it will be useful,
12 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
13 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 .\" GNU General Public License for more details.
16 .\" You should have received a copy of the GNU General Public
17 .\" License along with this manual; if not, see
18 .\" <http://www.gnu.org/licenses/>.
21 .\" 2007-04-30: mtk, Added description of epoll_pwait()
23 .TH EPOLL_WAIT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
25 epoll_wait, epoll_pwait, epoll_pwait2 \- wait for an I/O event on an epoll file descriptor
28 .B #include <sys/epoll.h>
30 .BI "int epoll_wait(int " epfd ", struct epoll_event *" events ,
31 .BI " int " maxevents ", int " timeout );
32 .BI "int epoll_pwait(int " epfd ", struct epoll_event *" events ,
33 .BI " int " maxevents ", int " timeout ,
34 .BI " const sigset_t *" sigmask );
35 .BI "int epoll_pwait2(int " epfd ", struct epoll_event *" events ,
36 .BI " int " maxevents ", const struct timespec *" timeout ,
37 .BI " const sigset_t *" sigmask );
38 .\" FIXME: Check if glibc has added a wrapper for epoll_pwait2(),
39 .\" and if so, check the prototype.
40 .\" https://sourceware.org/bugzilla/show_bug.cgi?id=27359
45 system call waits for events on the
47 instance referred to by the file descriptor
49 The buffer pointed to by
51 is used to return information from the ready list
52 about file descriptors in the interest list that
53 have some events available.
60 argument must be greater than zero.
64 argument specifies the number of milliseconds that
67 Time is measured against the
73 will block until either:
75 a file descriptor delivers an event;
77 the call is interrupted by a signal handler; or
83 interval will be rounded up to the system clock granularity,
84 and kernel scheduling delays mean that the blocking interval
85 may overrun by a small amount.
90 to block indefinitely, while specifying a
94 to return immediately, even if no events are available.
102 typedef union epoll_data {
110 uint32_t events; /* Epoll events */
111 epoll_data_t data; /* User data variable */
118 field of each returned
120 structure contains the same data as was specified
121 in the most recent call to
123 .RB ( EPOLL_CTL_ADD ", " EPOLL_CTL_MOD )
124 for the corresponding open file descriptor.
128 field is a bit mask that indicates the events that have occurred for the
129 corresponding open file description.
132 for a list of the bits that may appear in this mask.
135 The relationship between
139 is analogous to the relationship between
146 allows an application to safely wait until either a file descriptor
147 becomes ready or until a signal is caught.
155 ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
161 executing the following calls:
167 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
168 ready = epoll_wait(epfd, &events, maxevents, timeout);
169 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
175 argument may be specified as NULL, in which case
183 system call is equivalent to
188 It takes an argument of type
190 to be able to specify nanosecond resolution timeout.
191 This argument functions the same as in
199 can block indefinitely.
203 returns the number of file descriptors ready for the requested I/O, or zero
204 if no file descriptor became ready during the requested
211 is set to indicate the error.
216 is not a valid file descriptor.
219 The memory area pointed to by
221 is not accessible with write permissions.
224 The call was interrupted by a signal handler before either (1) any of the
225 requested events occurred or (2) the
236 is less than or equal to zero.
239 was added to the kernel in version 2.6.
240 .\" To be precise: kernel 2.5.44.
241 .\" The interface should be finalized by Linux kernel 2.5.66.
242 Library support is provided in glibc starting with version 2.3.2.
245 was added to Linux in kernel 2.6.19.
246 Library support is provided in glibc starting with version 2.6.
249 was added to Linux in kernel 5.11.
257 While one thread is blocked in a call to
259 it is possible for another thread to add a file descriptor to the waited-upon
262 If the new file descriptor becomes ready,
269 file descriptors are ready when
271 is called, then successive
273 calls will round robin through the set of ready file descriptors.
274 This behavior helps avoid starvation scenarios,
275 where a process fails to notice that additional file descriptors
276 are ready because it focuses on a set of file descriptors that
277 are already known to be ready.
279 Note that it is possible to call
283 instance whose interest list is currently empty
284 (or whose interest list becomes empty because file descriptors are closed
285 or removed from the interest in another thread).
286 The call will block until some file descriptor is later added to the
287 interest list (in another thread) and that file descriptor becomes ready.
288 .SS C library/kernel differences
293 system calls have a sixth argument,
294 .IR "size_t sigsetsize" ,
295 which specifies the size in bytes of the
300 wrapper function specifies this argument as a fixed value
302 .IR sizeof(sigset_t) ).
304 In kernels before 2.6.37, a
306 value larger than approximately
308 milliseconds is treated as \-1 (i.e., infinity).
309 Thus, for example, on a system where
314 this means that timeouts greater than 35.79 minutes are treated as infinity.
316 .BR epoll_create (2),