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 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

RETURN VALUE

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

ERRORS

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

VERSIONS

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

CONFORMING TO

109       epoll_wait() is Linux-specific.
110

NOTES

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       If more than maxevents file descriptors are ready when epoll_wait()  is
118       called, then successive epoll_wait() calls will round robin through the
119       set of ready file descriptors.  This behavior  helps  avoid  starvation
120       scenarios,  where  a  process  fails  to  notice  that  additional file
121       descriptors are ready because it focuses on a set of  file  descriptors
122       that are already known to be ready.
123
124       Note  that  it  is  possible  to call epoll_wait() on an epoll instance
125       whose interest list is currently empty (or whose interest list  becomes
126       empty  because file descriptors are closed or removed from the interest
127       in another thread).  The call will block until some file descriptor  is
128       later  added  to  the  interest  list (in another thread) and that file
129       descriptor becomes ready.
130

BUGS

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

SEE ALSO

145       epoll_create(2), epoll_ctl(2), epoll(7)
146

COLOPHON

148       This  page  is  part of release 5.02 of the Linux man-pages project.  A
149       description of the project, information about reporting bugs,  and  the
150       latest     version     of     this    page,    can    be    found    at
151       https://www.kernel.org/doc/man-pages/.
152
153
154
155Linux                             2019-03-06                     EPOLL_WAIT(2)
Impressum