]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/epoll_wait.2
man*/: srcfix (Use .P instead of .PP or .LP)
[thirdparty/man-pages.git] / man2 / epoll_wait.2
CommitLineData
fea681da 1.\" Copyright (C) 2003 Davide Libenzi
4366109b 2.\" Davide Libenzi <davidel@xmailserver.org>
23a169f7 3.\" and Copyright 2007, 2012, 2014, 2018 Michael Kerrisk <tk.manpages@gmail.com>
fea681da 4.\"
e4a74ca8 5.\" SPDX-License-Identifier: GPL-2.0-or-later
fea681da 6.\"
3996edf6 7.\" 2007-04-30: mtk, Added description of epoll_pwait()
e0614973 8.\"
4c1c5274 9.TH epoll_wait 2 (date) "Linux man-pages (unreleased)"
fea681da 10.SH NAME
15f0b7af
AC
11epoll_wait, epoll_pwait, epoll_pwait2 \-
12wait for an I/O event on an epoll file descriptor
6c382561
AC
13.SH LIBRARY
14Standard C library
8fc3b2cf 15.RI ( libc ", " \-lc )
fea681da 16.SH SYNOPSIS
616c0fd3 17.nf
fea681da 18.B #include <sys/epoll.h>
c6d039a3 19.P
c13182ef 20.BI "int epoll_wait(int " epfd ", struct epoll_event *" events ,
3996edf6 21.BI " int " maxevents ", int " timeout );
35f0f2f9 22.BI "int epoll_pwait(int " epfd ", struct epoll_event *" events ,
988db661 23.BI " int " maxevents ", int " timeout ,
bc19b86a 24.BI " const sigset_t *_Nullable " sigmask );
ba47eb5e 25.BI "int epoll_pwait2(int " epfd ", struct epoll_event *" events ,
bc19b86a
AC
26.BI " int " maxevents ", \
27const struct timespec *_Nullable " timeout ,
28.BI " const sigset_t *_Nullable " sigmask );
616c0fd3 29.fi
fea681da 30.SH DESCRIPTION
35f0f2f9
MK
31The
32.BR epoll_wait ()
33system call waits for events on the
284976f8 34.BR epoll (7)
8483a88c
MK
35instance referred to by the file descriptor
36.IR epfd .
23a169f7 37The buffer pointed to by
fea681da 38.I events
23a169f7
MK
39is used to return information from the ready list
40about file descriptors in the interest list that
41have some events available.
fea681da
MK
42Up to
43.I maxevents
44are returned by
2777b1ca 45.BR epoll_wait ().
fea681da
MK
46The
47.I maxevents
c4bb193f 48argument must be greater than zero.
c6d039a3 49.P
f07cd91a 50The
ae3faf4b 51.I timeout
3c9b77d5 52argument specifies the number of milliseconds that
f07cd91a
MK
53.BR epoll_wait ()
54will block.
c1a2cf47
MC
55Time is measured against the
56.B CLOCK_MONOTONIC
57clock.
c6d039a3 58.P
23a169f7
MK
59A call to
60.BR epoll_wait ()
61will block until either:
cdede5cd 62.IP \[bu] 3
40df3d00 63a file descriptor delivers an event;
cdede5cd 64.IP \[bu]
40df3d00 65the call is interrupted by a signal handler; or
cdede5cd 66.IP \[bu]
af8ad761 67the timeout expires.
c6d039a3 68.P
40df3d00
MK
69Note that the
70.I timeout
71interval will be rounded up to the system clock granularity,
f07cd91a 72and kernel scheduling delays mean that the blocking interval
40df3d00 73may overrun by a small amount.
c13182ef 74Specifying a
fea681da 75.I timeout
70a6338b 76of \-1 causes
2777b1ca 77.BR epoll_wait ()
70a6338b 78to block indefinitely, while specifying a
fea681da 79.I timeout
70a6338b 80equal to zero cause
2777b1ca 81.BR epoll_wait ()
70a6338b 82to return immediately, even if no events are available.
c6d039a3 83.P
fea681da 84The
8478ee02 85.I struct epoll_event
4ecb3859
AC
86is described in
87.BR epoll_event (3type).
c6d039a3 88.P
fea681da
MK
89The
90.I data
23a169f7
MK
91field of each returned
92.I epoll_event
93structure contains the same data as was specified
991c24c8 94in the most recent call to
fea681da 95.BR epoll_ctl (2)
991c24c8 96.RB ( EPOLL_CTL_ADD ", " EPOLL_CTL_MOD )
23a169f7 97for the corresponding open file descriptor.
c6d039a3 98.P
1b564a4b 99The
fea681da 100.I events
23a169f7
MK
101field is a bit mask that indicates the events that have occurred for the
102corresponding open file description.
103See
104.BR epoll_ctl (2)
105for a list of the bits that may appear in this mask.
106.\"
3996edf6
MK
107.SS epoll_pwait()
108The relationship between
109.BR epoll_wait ()
110and
111.BR epoll_pwait ()
112is analogous to the relationship between
0bfa087b 113.BR select (2)
3996edf6 114and
0bfa087b 115.BR pselect (2):
3996edf6 116like
0bfa087b 117.BR pselect (2),
3996edf6
MK
118.BR epoll_pwait ()
119allows an application to safely wait until either a file descriptor
120becomes ready or until a signal is caught.
c6d039a3 121.P
3996edf6
MK
122The following
123.BR epoll_pwait ()
124call:
c6d039a3 125.P
47f743f1
MK
126.in +4n
127.EX
128ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
129.EE
130.in
c6d039a3 131.P
3996edf6
MK
132is equivalent to
133.I atomically
134executing the following calls:
c6d039a3 135.P
47f743f1
MK
136.in +4n
137.EX
138sigset_t origmask;
fe5dba13 139\&
47f743f1
MK
140pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
141ready = epoll_wait(epfd, &events, maxevents, timeout);
142pthread_sigmask(SIG_SETMASK, &origmask, NULL);
143.EE
144.in
c6d039a3 145.P
c98759f3
MK
146The
147.I sigmask
148argument may be specified as NULL, in which case
149.BR epoll_pwait ()
150is equivalent to
151.BR epoll_wait ().
5efa68d5
MK
152.\"
153.SS epoll_pwait2()
ba47eb5e
WB
154The
155.BR epoll_pwait2 ()
156system call is equivalent to
157.BR epoll_pwait ()
158except for the
159.I timeout
5efa68d5
MK
160argument.
161It takes an argument of type
ba47eb5e 162.I timespec
5efa68d5
MK
163to be able to specify nanosecond resolution timeout.
164This argument functions the same as in
ba47eb5e
WB
165.BR pselect (2)
166and
167.BR ppoll (2).
168If
169.I timeout
170is NULL, then
171.BR epoll_pwait2 ()
172can block indefinitely.
47297adb 173.SH RETURN VALUE
2ae5c63a 174On success,
2777b1ca 175.BR epoll_wait ()
fea681da
MK
176returns the number of file descriptors ready for the requested I/O, or zero
177if no file descriptor became ready during the requested
178.I timeout
c13182ef 179milliseconds.
2ae5c63a 180On failure,
2777b1ca 181.BR epoll_wait ()
fea681da
MK
182returns \-1 and
183.I errno
f6a4078b 184is set to indicate the error.
fea681da
MK
185.SH ERRORS
186.TP
187.B EBADF
188.I epfd
189is not a valid file descriptor.
190.TP
191.B EFAULT
192The memory area pointed to by
193.I events
194is not accessible with write permissions.
195.TP
c5a2d222 196.B EINTR
db6f9ec8
MK
197The call was interrupted by a signal handler before either (1) any of the
198requested events occurred or (2) the
c5a2d222 199.I timeout
01538d0d
MK
200expired; see
201.BR signal (7).
c5a2d222 202.TP
fea681da 203.B EINVAL
0daa9e92 204.I epfd
fea681da
MK
205is not an
206.B epoll
3d9a2200 207file descriptor, or
fea681da 208.I maxevents
3d9a2200 209is less than or equal to zero.
4131356c
AC
210.SH STANDARDS
211Linux.
212.SH HISTORY
213.TP
cb22cfb4 214.BR epoll_wait ()
4131356c
AC
215Linux 2.6,
216.\" To be precise: Linux 2.5.44.
b324e17d 217.\" The interface should be finalized by Linux 2.5.66.
4131356c
AC
218glibc 2.3.2.
219.TP
a1d5f77c 220.BR epoll_pwait ()
4131356c
AC
221Linux 2.6.19,
222glibc 2.6.
223.TP
1e6910c9 224.BR epoll_pwait2 ()
4131356c 225Linux 5.11.
7396b79c
MK
226.SH NOTES
227While one thread is blocked in a call to
49853640 228.BR epoll_wait (),
7396b79c
MK
229it is possible for another thread to add a file descriptor to the waited-upon
230.B epoll
231instance.
232If the new file descriptor becomes ready,
233it will cause the
234.BR epoll_wait ()
235call to unblock.
c6d039a3 236.P
fc9294cb
MK
237If more than
238.I maxevents
239file descriptors are ready when
240.BR epoll_wait ()
241is called, then successive
242.BR epoll_wait ()
243calls will round robin through the set of ready file descriptors.
244This behavior helps avoid starvation scenarios,
245where a process fails to notice that additional file descriptors
246are ready because it focuses on a set of file descriptors that
247are already known to be ready.
c6d039a3 248.P
e3a60d1c 249Note that it is possible to call
67378c48 250.BR epoll_wait ()
e3a60d1c
MK
251on an
252.B epoll
253instance whose interest list is currently empty
254(or whose interest list becomes empty because file descriptors are closed
255or removed from the interest in another thread).
256The call will block until some file descriptor is later added to the
257interest list (in another thread) and that file descriptor becomes ready.
0722a578 258.SS C library/kernel differences
81428c3a
MK
259The raw
260.BR epoll_pwait ()
ba47eb5e
WB
261and
262.BR epoll_pwait2 ()
263system calls have a sixth argument,
81428c3a
MK
264.IR "size_t sigsetsize" ,
265which specifies the size in bytes of the
1ae6b2c7 266.I sigmask
81428c3a
MK
267argument.
268The glibc
269.BR epoll_pwait ()
270wrapper function specifies this argument as a fixed value
271(equal to
272.IR sizeof(sigset_t) ).
099b33fb 273.SH BUGS
b324e17d 274Before Linux 2.6.37, a
099b33fb
AC
275.I timeout
276value larger than approximately
277.I LONG_MAX / HZ
278milliseconds is treated as \-1 (i.e., infinity).
279Thus, for example, on a system where
280.I sizeof(long)
281is 4 and the kernel
282.I HZ
283value is 1000,
284this means that timeouts greater than 35.79 minutes are treated as infinity.
47297adb 285.SH SEE ALSO
fea681da
MK
286.BR epoll_create (2),
287.BR epoll_ctl (2),
2315114c 288.BR epoll (7)