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 (date) "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 *_Nullable " sigmask );
25 .BI "int epoll_pwait2(int " epfd ", struct epoll_event *" events ,
26 .BI " int " maxevents ", \
27 const struct timespec *_Nullable " timeout ,
28 .BI " const sigset_t *_Nullable " sigmask );
33 system call waits for events on the
35 instance referred to by the file descriptor
37 The buffer pointed to by
39 is used to return information from the ready list
40 about file descriptors in the interest list that
41 have some events available.
48 argument must be greater than zero.
52 argument specifies the number of milliseconds that
55 Time is measured against the
61 will block until either:
63 a file descriptor delivers an event;
65 the call is interrupted by a signal handler; or
71 interval will be rounded up to the system clock granularity,
72 and kernel scheduling delays mean that the blocking interval
73 may overrun by a small amount.
78 to block indefinitely, while specifying a
82 to return immediately, even if no events are available.
87 .BR epoll_event (3type).
91 field of each returned
93 structure contains the same data as was specified
94 in the most recent call to
96 .RB ( EPOLL_CTL_ADD ", " EPOLL_CTL_MOD )
97 for the corresponding open file descriptor.
101 field is a bit mask that indicates the events that have occurred for the
102 corresponding open file description.
105 for a list of the bits that may appear in this mask.
108 The relationship between
112 is analogous to the relationship between
119 allows an application to safely wait until either a file descriptor
120 becomes ready or until a signal is caught.
128 ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
134 executing the following calls:
140 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
141 ready = epoll_wait(epfd, &events, maxevents, timeout);
142 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
148 argument may be specified as NULL, in which case
156 system call is equivalent to
161 It takes an argument of type
163 to be able to specify nanosecond resolution timeout.
164 This argument functions the same as in
172 can block indefinitely.
176 returns the number of file descriptors ready for the requested I/O, or zero
177 if no file descriptor became ready during the requested
184 is set to indicate the error.
189 is not a valid file descriptor.
192 The memory area pointed to by
194 is not accessible with write permissions.
197 The call was interrupted by a signal handler before either (1) any of the
198 requested events occurred or (2) the
209 is less than or equal to zero.
212 was added in Linux 2.6.
213 .\" To be precise: kernel 2.5.44.
214 .\" The interface should be finalized by Linux 2.5.66.
215 Library support is provided in glibc 2.3.2.
218 was added in Linux 2.6.19.
219 Library support is provided in glibc 2.6.
222 was added in Linux 5.11.
230 While one thread is blocked in a call to
232 it is possible for another thread to add a file descriptor to the waited-upon
235 If the new file descriptor becomes ready,
242 file descriptors are ready when
244 is called, then successive
246 calls will round robin through the set of ready file descriptors.
247 This behavior helps avoid starvation scenarios,
248 where a process fails to notice that additional file descriptors
249 are ready because it focuses on a set of file descriptors that
250 are already known to be ready.
252 Note that it is possible to call
256 instance whose interest list is currently empty
257 (or whose interest list becomes empty because file descriptors are closed
258 or removed from the interest in another thread).
259 The call will block until some file descriptor is later added to the
260 interest list (in another thread) and that file descriptor becomes ready.
261 .SS C library/kernel differences
266 system calls have a sixth argument,
267 .IR "size_t sigsetsize" ,
268 which specifies the size in bytes of the
273 wrapper function specifies this argument as a fixed value
275 .IR sizeof(sigset_t) ).
277 Before Linux 2.6.37, a
279 value larger than approximately
281 milliseconds is treated as \-1 (i.e., infinity).
282 Thus, for example, on a system where
287 this means that timeouts greater than 35.79 minutes are treated as infinity.
289 .BR epoll_create (2),