1EPOLL_WAIT(2)              Linux Programmer's Manual             EPOLL_WAIT(2)
2
3
4

NAME

6       epoll_wait,  epoll_pwait  -  wait  for  an  I/O  event on an epoll file
7       descriptor
8

SYNOPSIS

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

DESCRIPTION

19       The epoll_wait() system call waits for events on the epoll(7)  instance
20       referred  to  by  the  file  descriptor epfd.  The buffer pointed to by
21       events is used to return information from the  ready  list  about  file
22       descriptors  in  the interest list that have some events available.  Up
23       to maxevents are returned by epoll_wait().  The maxevents argument must
24       be greater than zero.
25
26       The   timeout  argument  specifies  the  number  of  milliseconds  that
27       epoll_wait() will block.  Time is measured against the  CLOCK_MONOTONIC
28       clock.
29
30       A call to epoll_wait() will block until either:
31
32       · a file descriptor delivers an event;
33
34       · the call is interrupted by a signal handler; or
35
36       · the timeout expires.
37
38       Note  that  the timeout interval will be rounded up to the system clock
39       granularity, and kernel scheduling delays mean that the blocking inter‐
40       val  may  overrun by a small amount.  Specifying a timeout of -1 causes
41       epoll_wait() to block indefinitely, while specifying a timeout equal to
42       zero  cause  epoll_wait()  to return immediately, even if no events are
43       available.
44
45       The struct epoll_event is defined as:
46
47           typedef union epoll_data {
48               void    *ptr;
49               int      fd;
50               uint32_t u32;
51               uint64_t u64;
52           } epoll_data_t;
53
54           struct epoll_event {
55               uint32_t     events;    /* Epoll events */
56               epoll_data_t data;      /* User data variable */
57           };
58
59       The data field of each returned epoll_event structure contains the same
60       data  as  was  specified  in  the  most  recent  call  to  epoll_ctl(2)
61       (EPOLL_CTL_ADD, EPOLL_CTL_MOD) for the corresponding open file descrip‐
62       tor.
63
64       The  events  field  is  a  bit mask that indicates the events that have
65       occurred for the corresponding open file description.  See epoll_ctl(2)
66       for a list of the bits that may appear in this mask.
67
68   epoll_pwait()
69       The relationship between epoll_wait() and epoll_pwait() is analogous to
70       the relationship between select(2)  and  pselect(2):  like  pselect(2),
71       epoll_pwait()  allows an application to safely wait until either a file
72       descriptor becomes ready or until a signal is caught.
73
74       The following epoll_pwait() call:
75
76           ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
77
78       is equivalent to atomically executing the following calls:
79
80           sigset_t origmask;
81
82           pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
83           ready = epoll_wait(epfd, &events, maxevents, timeout);
84           pthread_sigmask(SIG_SETMASK, &origmask, NULL);
85
86       The  sigmask  argument  may  be  specified  as  NULL,  in  which   case
87       epoll_pwait() is equivalent to epoll_wait().
88

RETURN VALUE

90       When  successful,  epoll_wait()  returns the number of file descriptors
91       ready for the requested I/O, or zero if no file descriptor became ready
92       during  the  requested  timeout  milliseconds.   When  an error occurs,
93       epoll_wait() returns -1 and errno is set appropriately.
94

ERRORS

96       EBADF  epfd is not a valid file descriptor.
97
98       EFAULT The memory area pointed to by  events  is  not  accessible  with
99              write permissions.
100
101       EINTR  The  call  was interrupted by a signal handler before either (1)
102              any of the requested events occurred or (2) the timeout expired;
103              see signal(7).
104
105       EINVAL epfd  is not an epoll file descriptor, or maxevents is less than
106              or equal to zero.
107

VERSIONS

109       epoll_wait() was added to the kernel in version 2.6.   Library  support
110       is provided in glibc starting with version 2.3.2.
111
112       epoll_pwait()  was added to Linux in kernel 2.6.19.  Library support is
113       provided in glibc starting with version 2.6.
114

CONFORMING TO

116       epoll_wait() is Linux-specific.
117

NOTES

119       While one thread is blocked in a call to epoll_wait(), it  is  possible
120       for  another  thread  to add a file descriptor to the waited-upon epoll
121       instance.  If the new file descriptor becomes ready, it will cause  the
122       epoll_wait() call to unblock.
123
124       If  more than maxevents file descriptors are ready when epoll_wait() is
125       called, then successive epoll_wait() calls will round robin through the
126       set  of  ready  file descriptors.  This behavior helps avoid starvation
127       scenarios, where  a  process  fails  to  notice  that  additional  file
128       descriptors  are  ready because it focuses on a set of file descriptors
129       that are already known to be ready.
130
131       Note that it is possible to call  epoll_wait()  on  an  epoll  instance
132       whose  interest list is currently empty (or whose interest list becomes
133       empty because file descriptors are closed or removed from the  interest
134       in  another thread).  The call will block until some file descriptor is
135       later added to the interest list (in  another  thread)  and  that  file
136       descriptor becomes ready.
137

BUGS

139       In  kernels  before  2.6.37,  a timeout value larger than approximately
140       LONG_MAX / HZ milliseconds is treated as -1  (i.e.,  infinity).   Thus,
141       for  example,  on  a  system  where sizeof(long) is 4 and the kernel HZ
142       value is 1000, this means that timeouts greater than 35.79 minutes  are
143       treated as infinity.
144
145   C library/kernel differences
146       The  raw epoll_pwait() system call has a sixth argument, size_t sigset‐
147       size, which specifies the size in bytes of the sigmask  argument.   The
148       glibc epoll_pwait() wrapper function specifies this argument as a fixed
149       value (equal to sizeof(sigset_t)).
150

SEE ALSO

152       epoll_create(2), epoll_ctl(2), epoll(7)
153

COLOPHON

155       This page is part of release 5.07 of the Linux  man-pages  project.   A
156       description  of  the project, information about reporting bugs, and the
157       latest    version    of    this    page,    can     be     found     at
158       https://www.kernel.org/doc/man-pages/.
159
160
161
162Linux                             2020-04-11                     EPOLL_WAIT(2)
Impressum