1EPOLL_WAIT(2) Linux Programmer's Manual EPOLL_WAIT(2)
2
3
4
6 epoll_wait, epoll_pwait - wait for an I/O event on an epoll file
7 descriptor
8
10 #include <sys/epoll.h>
11
12 int epoll_wait(int epfd, struct epoll_event *events,
13 int maxevents, int timeout);
14 int epoll_pwait(int epfd, struct epoll_event *events,
15 int maxevents, int timeout,
16 const sigset_t *sigmask);
17
19 The epoll_wait() system call waits for events on the epoll(7) instance
20 referred to by the file descriptor epfd. The memory area pointed to by
21 events will contain the events that will be available for the caller.
22 Up to maxevents are returned by epoll_wait(). The maxevents argument
23 must be greater than zero.
24
25 The timeout argument specifies the number of milliseconds that
26 epoll_wait() will block. Time is measured against the CLOCK_MONOTONIC
27 clock. The call will block until either:
28
29 * a file descriptor delivers an event;
30
31 * the call is interrupted by a signal handler; or
32
33 * the timeout expires.
34
35 Note that the timeout interval will be rounded up to the system clock
36 granularity, and kernel scheduling delays mean that the blocking inter‐
37 val may overrun by a small amount. Specifying a timeout of -1 causes
38 epoll_wait() to block indefinitely, while specifying a timeout equal to
39 zero cause epoll_wait() to return immediately, even if no events are
40 available.
41
42 The struct epoll_event is defined as:
43
44 typedef union epoll_data {
45 void *ptr;
46 int fd;
47 uint32_t u32;
48 uint64_t u64;
49 } epoll_data_t;
50
51 struct epoll_event {
52 uint32_t events; /* Epoll events */
53 epoll_data_t data; /* User data variable */
54 };
55
56 The data field of each returned structure contains the same data as was
57 specified in the most recent call to epoll_ctl(2) (EPOLL_CTL_ADD,
58 EPOLL_CTL_MOD) for the corresponding open file description. The events
59 field contains the returned event bit field.
60
61 epoll_pwait()
62 The relationship between epoll_wait() and epoll_pwait() is analogous to
63 the relationship between select(2) and pselect(2): like pselect(2),
64 epoll_pwait() allows an application to safely wait until either a file
65 descriptor becomes ready or until a signal is caught.
66
67 The following epoll_pwait() call:
68
69 ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
70
71 is equivalent to atomically executing the following calls:
72
73 sigset_t origmask;
74
75 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
76 ready = epoll_wait(epfd, &events, maxevents, timeout);
77 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
78
79 The sigmask argument may be specified as NULL, in which case
80 epoll_pwait() is equivalent to epoll_wait().
81
83 When successful, epoll_wait() returns the number of file descriptors
84 ready for the requested I/O, or zero if no file descriptor became ready
85 during the requested timeout milliseconds. When an error occurs,
86 epoll_wait() returns -1 and errno is set appropriately.
87
89 EBADF epfd is not a valid file descriptor.
90
91 EFAULT The memory area pointed to by events is not accessible with
92 write permissions.
93
94 EINTR The call was interrupted by a signal handler before either (1)
95 any of the requested events occurred or (2) the timeout expired;
96 see signal(7).
97
98 EINVAL epfd is not an epoll file descriptor, or maxevents is less than
99 or equal to zero.
100
102 epoll_wait() was added to the kernel in version 2.6. Library support
103 is provided in glibc starting with version 2.3.2.
104
105 epoll_pwait() was added to Linux in kernel 2.6.19. Library support is
106 provided in glibc starting with version 2.6.
107
109 epoll_wait() is Linux-specific.
110
112 While one thread is blocked in a call to epoll_pwait(), it is possible
113 for another thread to add a file descriptor to the waited-upon epoll
114 instance. If the new file descriptor becomes ready, it will cause the
115 epoll_wait() call to unblock.
116
117 For a discussion of what may happen if a file descriptor in an epoll
118 instance being monitored by epoll_wait() is closed in another thread,
119 see select(2).
120
122 In kernels before 2.6.37, a timeout value larger than approximately
123 LONG_MAX / HZ milliseconds is treated as -1 (i.e., infinity). Thus,
124 for example, on a system where sizeof(long) is 4 and the kernel HZ
125 value is 1000, this means that timeouts greater than 35.79 minutes are
126 treated as infinity.
127
128 C library/kernel differences
129 The raw epoll_pwait() system call has a sixth argument, size_t sigset‐
130 size, which specifies the size in bytes of the sigmask argument. The
131 glibc epoll_pwait() wrapper function specifies this argument as a fixed
132 value (equal to sizeof(sigset_t)).
133
135 epoll_create(2), epoll_ctl(2), epoll(7)
136
138 This page is part of release 4.15 of the Linux man-pages project. A
139 description of the project, information about reporting bugs, and the
140 latest version of this page, can be found at
141 https://www.kernel.org/doc/man-pages/.
142
143
144
145Linux 2017-09-15 EPOLL_WAIT(2)