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 2020-04-11 "Linux" "Linux Programmer's Manual"
25 epoll_wait, epoll_pwait \- 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 );
39 system call waits for events on the
41 instance referred to by the file descriptor
43 The buffer pointed to by
45 is used to return information from the ready list
46 about file descriptors in the interest list that
47 have some events available.
54 argument must be greater than zero.
58 argument specifies the number of milliseconds that
61 Time is measured against the
67 will block until either:
69 a file descriptor delivers an event;
71 the call is interrupted by a signal handler; or
77 interval will be rounded up to the system clock granularity,
78 and kernel scheduling delays mean that the blocking interval
79 may overrun by a small amount.
84 to block indefinitely, while specifying a
88 to return immediately, even if no events are available.
96 typedef union epoll_data {
104 uint32_t events; /* Epoll events */
105 epoll_data_t data; /* User data variable */
112 field of each returned
114 structure contains the same data as was specified
115 in the most recent call to
117 .RB ( EPOLL_CTL_ADD ", " EPOLL_CTL_MOD )
118 for the corresponding open file descriptor.
122 field is a bit mask that indicates the events that have occurred for the
123 corresponding open file description.
126 for a list of the bits that may appear in this mask.
129 The relationship between
133 is analogous to the relationship between
140 allows an application to safely wait until either a file descriptor
141 becomes ready or until a signal is caught.
149 ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
155 executing the following calls:
161 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
162 ready = epoll_wait(epfd, &events, maxevents, timeout);
163 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
169 argument may be specified as NULL, in which case
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
180 When an error occurs,
184 is set appropriately.
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 to the kernel in version 2.6.
213 .\" To be precise: kernel 2.5.44.
214 .\" The interface should be finalized by Linux kernel 2.5.66.
215 Library support is provided in glibc starting with version 2.3.2.
218 was added to Linux in kernel 2.6.19.
219 Library support is provided in glibc starting with version 2.6.
224 While one thread is blocked in a call to
226 it is possible for another thread to add a file descriptor to the waited-upon
229 If the new file descriptor becomes ready,
236 file descriptors are ready when
238 is called, then successive
240 calls will round robin through the set of ready file descriptors.
241 This behavior helps avoid starvation scenarios,
242 where a process fails to notice that additional file descriptors
243 are ready because it focuses on a set of file descriptors that
244 are already known to be ready.
246 Note that it is possible to call
250 instance whose interest list is currently empty
251 (or whose interest list becomes empty because file descriptors are closed
252 or removed from the interest in another thread).
253 The call will block until some file descriptor is later added to the
254 interest list (in another thread) and that file descriptor becomes ready.
256 In kernels before 2.6.37, a
258 value larger than approximately
260 milliseconds is treated as \-1 (i.e., infinity).
261 Thus, for example, on a system where
266 this means that timeouts greater than 35.79 minutes are treated as infinity.
267 .SS C library/kernel differences
270 system call has a sixth argument,
271 .IR "size_t sigsetsize" ,
272 which specifies the size in bytes of the
277 wrapper function specifies this argument as a fixed value
279 .IR sizeof(sigset_t) ).
281 .BR epoll_create (2),