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 man-pages (unreleased)"
11 epoll_wait, epoll_pwait, epoll_pwait2 \-
12 wait for an I/O event on an epoll file descriptor
15 .RI ( libc ", " \-lc )
18 .B #include <sys/epoll.h>
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 );
32 system call waits for events on the
34 instance referred to by the file descriptor
36 The buffer pointed to by
38 is used to return information from the ready list
39 about file descriptors in the interest list that
40 have some events available.
47 argument must be greater than zero.
51 argument specifies the number of milliseconds that
54 Time is measured against the
60 will block until either:
62 a file descriptor delivers an event;
64 the call is interrupted by a signal handler; or
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.
77 to block indefinitely, while specifying a
81 to return immediately, even if no events are available.
86 .BR epoll_event (3type).
90 field of each returned
92 structure contains the same data as was specified
93 in the most recent call to
95 .RB ( EPOLL_CTL_ADD ", " EPOLL_CTL_MOD )
96 for the corresponding open file descriptor.
100 field is a bit mask that indicates the events that have occurred for the
101 corresponding open file description.
104 for a list of the bits that may appear in this mask.
107 The relationship between
111 is analogous to the relationship between
118 allows an application to safely wait until either a file descriptor
119 becomes ready or until a signal is caught.
127 ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
133 executing the following calls:
139 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
140 ready = epoll_wait(epfd, &events, maxevents, timeout);
141 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
147 argument may be specified as NULL, in which case
155 system call is equivalent to
160 It takes an argument of type
162 to be able to specify nanosecond resolution timeout.
163 This argument functions the same as in
171 can block indefinitely.
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
183 is set to indicate the error.
188 is not a valid file descriptor.
191 The memory area pointed to by
193 is not accessible with write permissions.
196 The call was interrupted by a signal handler before either (1) any of the
197 requested events occurred or (2) the
208 is less than or equal to zero.
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.
217 was added to Linux in kernel 2.6.19.
218 Library support is provided in glibc starting with version 2.6.
221 was added to Linux in kernel 5.11.
229 While one thread is blocked in a call to
231 it is possible for another thread to add a file descriptor to the waited-upon
234 If the new file descriptor becomes ready,
241 file descriptors are ready when
243 is called, then successive
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.
251 Note that it is possible to call
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
265 system calls have a sixth argument,
266 .IR "size_t sigsetsize" ,
267 which specifies the size in bytes of the
272 wrapper function specifies this argument as a fixed value
274 .IR sizeof(sigset_t) ).
276 In kernels before 2.6.37, a
278 value larger than approximately
280 milliseconds is treated as \-1 (i.e., infinity).
281 Thus, for example, on a system where
286 this means that timeouts greater than 35.79 minutes are treated as infinity.
288 .BR epoll_create (2),