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 .\" SPDX-License-Identifier: GPL-2.0-or-later
7 .\" 2007-04-30: mtk, Added description of epoll_pwait()
9 .TH EPOLL_WAIT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
11 epoll_wait, epoll_pwait, epoll_pwait2 \- wait for an I/O event on an epoll file descriptor
14 .RI ( libc ", " \-lc )
17 .B #include <sys/epoll.h>
19 .BI "int epoll_wait(int " epfd ", struct epoll_event *" events ,
20 .BI " int " maxevents ", int " timeout );
21 .BI "int epoll_pwait(int " epfd ", struct epoll_event *" events ,
22 .BI " int " maxevents ", int " timeout ,
23 .BI " const sigset_t *" sigmask );
24 .BI "int epoll_pwait2(int " epfd ", struct epoll_event *" events ,
25 .BI " int " maxevents ", const struct timespec *" timeout ,
26 .BI " const sigset_t *" sigmask );
31 system call waits for events on the
33 instance referred to by the file descriptor
35 The buffer pointed to by
37 is used to return information from the ready list
38 about file descriptors in the interest list that
39 have some events available.
46 argument must be greater than zero.
50 argument specifies the number of milliseconds that
53 Time is measured against the
59 will block until either:
61 a file descriptor delivers an event;
63 the call is interrupted by a signal handler; or
69 interval will be rounded up to the system clock granularity,
70 and kernel scheduling delays mean that the blocking interval
71 may overrun by a small amount.
76 to block indefinitely, while specifying a
80 to return immediately, even if no events are available.
88 typedef union epoll_data {
96 uint32_t events; /* Epoll events */
97 epoll_data_t data; /* User data variable */
104 field of each returned
106 structure contains the same data as was specified
107 in the most recent call to
109 .RB ( EPOLL_CTL_ADD ", " EPOLL_CTL_MOD )
110 for the corresponding open file descriptor.
114 field is a bit mask that indicates the events that have occurred for the
115 corresponding open file description.
118 for a list of the bits that may appear in this mask.
121 The relationship between
125 is analogous to the relationship between
132 allows an application to safely wait until either a file descriptor
133 becomes ready or until a signal is caught.
141 ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
147 executing the following calls:
153 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
154 ready = epoll_wait(epfd, &events, maxevents, timeout);
155 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
161 argument may be specified as NULL, in which case
169 system call is equivalent to
174 It takes an argument of type
176 to be able to specify nanosecond resolution timeout.
177 This argument functions the same as in
185 can block indefinitely.
189 returns the number of file descriptors ready for the requested I/O, or zero
190 if no file descriptor became ready during the requested
197 is set to indicate the error.
202 is not a valid file descriptor.
205 The memory area pointed to by
207 is not accessible with write permissions.
210 The call was interrupted by a signal handler before either (1) any of the
211 requested events occurred or (2) the
222 is less than or equal to zero.
225 was added to the kernel in version 2.6.
226 .\" To be precise: kernel 2.5.44.
227 .\" The interface should be finalized by Linux kernel 2.5.66.
228 Library support is provided in glibc starting with version 2.3.2.
231 was added to Linux in kernel 2.6.19.
232 Library support is provided in glibc starting with version 2.6.
235 was added to Linux in kernel 5.11.
243 While one thread is blocked in a call to
245 it is possible for another thread to add a file descriptor to the waited-upon
248 If the new file descriptor becomes ready,
255 file descriptors are ready when
257 is called, then successive
259 calls will round robin through the set of ready file descriptors.
260 This behavior helps avoid starvation scenarios,
261 where a process fails to notice that additional file descriptors
262 are ready because it focuses on a set of file descriptors that
263 are already known to be ready.
265 Note that it is possible to call
269 instance whose interest list is currently empty
270 (or whose interest list becomes empty because file descriptors are closed
271 or removed from the interest in another thread).
272 The call will block until some file descriptor is later added to the
273 interest list (in another thread) and that file descriptor becomes ready.
274 .SS C library/kernel differences
279 system calls have a sixth argument,
280 .IR "size_t sigsetsize" ,
281 which specifies the size in bytes of the
286 wrapper function specifies this argument as a fixed value
288 .IR sizeof(sigset_t) ).
290 In kernels before 2.6.37, a
292 value larger than approximately
294 milliseconds is treated as \-1 (i.e., infinity).
295 Thus, for example, on a system where
300 this means that timeouts greater than 35.79 minutes are treated as infinity.
302 .BR epoll_create (2),