1 .\" Copyright (C) 2003 Davide Libenzi
2 .\" Davide Libenzi <davidel@xmailserver.org>
3 .\" and Copyright 2009, 2014, 2016, 2018, 2019 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 .TH EPOLL_CTL 2 2019-03-06 "Linux" "Linux Programmer's Manual"
23 epoll_ctl \- control interface for an epoll file descriptor
25 .B #include <sys/epoll.h>
27 .BI "int epoll_ctl(int " epfd ", int " op ", int " fd \
28 ", struct epoll_event *" event );
30 This system call is used to add, modify, or remove
31 entries in the interest list of the
34 referred to by the file descriptor
36 It requests that the operation
38 be performed for the target file descriptor,
46 Add an entry to the interest list of the epoll file descriptor,
48 The entry includes the file descriptor,
50 a reference to the corresponding open file description (see
54 and the settings specified in
58 Change the settings associated with
60 in the interest list to the new settings specified in
64 Remove (deregister) the target file descriptor
66 from the interest list.
69 argument is ignored and can be NULL (but see BUGS below).
73 argument describes the object linked to the file descriptor
81 typedef union epoll_data {
89 uint32_t events; /* Epoll events */
90 epoll_data_t data; /* User data variable */
99 structure specifies data that the kernel should save and then return (via
101 when this file descriptor becomes ready.
107 structure is a bit mask composed by ORing together zero or more of
108 the following available event types:
111 The associated file is available for
116 The associated file is available for
120 .BR EPOLLRDHUP " (since Linux 2.6.17)"
121 Stream socket peer closed connection,
122 or shut down writing half of connection.
123 (This flag is especially useful for writing simple code to detect
124 peer shutdown when using edge-triggered monitoring.)
127 There is an exceptional condition on the file descriptor.
128 See the discussion of
134 Error condition happened on the associated file descriptor.
135 This event is also reported for the write end of a pipe when the read end
139 will always report for this event; it is not necessary to set it in
145 Hang up happened on the associated file descriptor.
148 will always wait for this event; it is not necessary to set it in
153 Note that when reading from a channel such as a pipe or a stream socket,
154 this event merely indicates that the peer closed its end of the channel.
155 Subsequent reads from the channel will return 0 (end of file)
156 only after all outstanding data in the channel has been consumed.
159 Requests edge-triggered notification for the associated file descriptor.
160 The default behavior for
165 for more detailed information about edge-triggered and
166 level-triggered notification.
168 This flag is an input flag for the
172 it is never returned by
175 .BR EPOLLONESHOT " (since Linux 2.6.2)"
176 Requests one-shot notification for the associated file descriptor.
177 This means that after an event notified for the file descriptor by
179 the file descriptor is disabled in the interest list and no other events
180 will be reported by the
187 to rearm the file descriptor with a new event mask.
189 This flag is an input flag for the
193 it is never returned by
196 .BR EPOLLWAKEUP " (since Linux 3.5)"
197 .\" commit 4d7e30d98939a0340022ccd49325a3d70f7e0238
202 are clear and the process has the
205 ensure that the system does not enter "suspend" or
206 "hibernate" while this event is pending or being processed.
207 The event is considered as being "processed" from the time
208 when it is returned by a call to
210 until the next call to
215 the closure of that file descriptor,
216 the removal of the event file descriptor with
220 for the event file descriptor with
224 This flag is an input flag for the
228 it is never returned by
231 .BR EPOLLEXCLUSIVE " (since Linux 4.5)"
232 Sets an exclusive wakeup mode for the epoll file descriptor that is being
233 attached to the target file descriptor,
235 When a wakeup event occurs and multiple epoll file descriptors
236 are attached to the same target file using
238 one or more of the epoll file descriptors will receive an event with
240 The default in this scenario (when
242 is not set) is for all epoll file descriptors to receive an event.
244 is thus useful for avoiding thundering herd problems in certain scenarios.
246 If the same file descriptor is in multiple epoll instances,
249 flag, and others without, then events will be provided to all epoll
250 instances that did not specify
252 and at least one of the epoll instances that did specify
255 The following values may be specified in conjunction with
265 can also be specified, but this is not required:
266 as usual, these events are always reported if they occur,
267 regardless of whether they are specified in
269 Attempts to specify other values in
275 may be used only in an
277 operation; attempts to employ it with
288 pair yields an error.
295 and specifies the target file descriptor
297 as an epoll instance will likewise fail.
298 The error in all of these cases is
303 flag is an input flag for the
307 it is never returned by
313 When an error occurs,
317 is set appropriately.
324 is not a valid file descriptor.
330 and the supplied file descriptor
332 is already registered with this epoll instance.
343 or the requested operation
345 is not supported by this interface.
348 An invalid event type was specified along with
368 flag has previously been applied to this
378 refers to an epoll instance.
382 refers to an epoll instance and this
384 operation would result in a circular loop of epoll instances
385 monitoring one another.
395 is not registered with this epoll instance.
398 There was insufficient memory to handle the requested
404 .I /proc/sys/fs/epoll/max_user_watches
405 was encountered while trying to register
406 .RB ( EPOLL_CTL_ADD )
407 a new file descriptor on an epoll instance.
417 This error can occur if
419 refers to, for example, a regular file or a directory.
422 was added to the kernel in version 2.6.
423 .\" To be precise: kernel 2.5.44.
424 .\" The interface should be finalized by Linux kernel 2.5.66.
428 Library support is provided in glibc starting with version 2.3.2.
432 interface supports all file descriptors that support
435 In kernel versions before 2.6.9, the
437 operation required a non-null pointer in
439 even though this argument is ignored.
442 can be specified as NULL
445 Applications that need to be portable to kernels before 2.6.9
446 should specify a non-null pointer in
453 but the caller does not have the
454 .BR CAP_BLOCK_SUSPEND
458 .IR "silently ignored" .
459 This unfortunate behavior is necessary because no validity
460 checks were performed on the
462 argument in the original implementation, and the addition of the
464 with a check that caused the call to fail if the caller did not have the
466 capability caused a breakage in at least one existing user-space
467 application that happened to randomly (and uselessly) specify this bit.
468 .\" commit a8159414d7e3af7233e7a5a82d1c5d85379bd75c (behavior change)
469 .\" https://lwn.net/Articles/520198/
470 A robust application should therefore double check that it has the
472 capability if attempting to use the
476 .BR epoll_create (2),