1 .\" Copyright (C) 2003 Davide Libenzi
2 .\" Davide Libenzi <davidel@xmailserver.org>
4 .\" %%%LICENSE_START(GPLv2+_SW_3_PARA)
5 .\" This program is free software; you can redistribute it and/or modify
6 .\" it under the terms of the GNU General Public License as published by
7 .\" the Free Software Foundation; either version 2 of the License, or
8 .\" (at your option) any later version.
10 .\" This program is distributed in the hope that it will be useful,
11 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
12 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 .\" GNU General Public License for more details.
15 .\" You should have received a copy of the GNU General Public
16 .\" License along with this manual; if not, see
17 .\" <http://www.gnu.org/licenses/>.
20 .TH EPOLL_CTL 2 2017-09-15 "Linux" "Linux Programmer's Manual"
22 epoll_ctl \- control interface for an epoll file descriptor
24 .B #include <sys/epoll.h>
26 .BI "int epoll_ctl(int " epfd ", int " op ", int " fd \
27 ", struct epoll_event *" event );
29 This system call performs control operations on the
32 referred to by the file descriptor
34 It requests that the operation
36 be performed for the target file descriptor,
44 Register the target file descriptor
48 instance referred to by the file descriptor
50 and associate the event
52 with the internal file linked to
58 associated with the target file descriptor
62 Remove (deregister) the target file descriptor
66 instance referred to by
70 is ignored and can be NULL (but see BUGS below).
74 argument describes the object linked to the file descriptor
82 typedef union epoll_data {
90 uint32_t events; /* Epoll events */
91 epoll_data_t data; /* User data variable */
98 member is a bit mask composed by ORing together zero or more of
99 the following available event types:
102 The associated file is available for
107 The associated file is available for
111 .BR EPOLLRDHUP " (since Linux 2.6.17)"
112 Stream socket peer closed connection,
113 or shut down writing half of connection.
114 (This flag is especially useful for writing simple code to detect
115 peer shutdown when using Edge Triggered monitoring.)
118 There is an exceptional condition on the file descriptor.
119 See the discussion of
125 Error condition happened on the associated file descriptor.
126 This event is also reported for the write end of a pipe when the read end
129 will always report for this event; it is not necessary to set it in
133 Hang up happened on the associated file descriptor.
135 will always wait for this event; it is not necessary to set it in
138 Note that when reading from a channel such as a pipe or a stream socket,
139 this event merely indicates that the peer closed its end of the channel.
140 Subsequent reads from the channel will return 0 (end of file)
141 only after all outstanding data in the channel has been consumed.
144 Sets the Edge Triggered behavior for the associated file descriptor.
145 The default behavior for
150 for more detailed information about Edge and Level Triggered event
151 distribution architectures.
153 .BR EPOLLONESHOT " (since Linux 2.6.2)"
154 Sets the one-shot behavior for the associated file descriptor.
155 This means that after an event is pulled out with
157 the associated file descriptor is internally disabled and no other events
158 will be reported by the
165 to rearm the file descriptor with a new event mask.
167 .BR EPOLLWAKEUP " (since Linux 3.5)"
168 .\" commit 4d7e30d98939a0340022ccd49325a3d70f7e0238
173 are clear and the process has the
176 ensure that the system does not enter "suspend" or
177 "hibernate" while this event is pending or being processed.
178 The event is considered as being "processed" from the time
179 when it is returned by a call to
181 until the next call to
186 the closure of that file descriptor,
187 the removal of the event file descriptor with
191 for the event file descriptor with
195 .BR EPOLLEXCLUSIVE " (since Linux 4.5)"
196 Sets an exclusive wakeup mode for the epoll file descriptor that is being
197 attached to the target file descriptor,
199 When a wakeup event occurs and multiple epoll file descriptors
200 are attached to the same target file using
202 one or more of the epoll file descriptors will receive an event with
204 The default in this scenario (when
206 is not set) is for all epoll file descriptors to receive an event.
208 is thus useful for avoiding thundering herd problems in certain scenarios.
210 If the same file descriptor is in multiple epoll instances,
213 flag, and others without, then events will be provided to all epoll
214 instances that did not specify
216 and at least one of the epoll instances that did specify
219 The following values may be specified in conjunction with
229 can also be specified, but this is not required:
230 as usual, these events are always reported if they occur,
231 regardless of whether they are specified in
233 Attempts to specify other values in
237 may be used only in an
239 operation; attempts to employ it with
250 pair yields an error.
257 and specifies the target file descriptor
259 as an epoll instance will likewise fail.
260 The error in all of these cases is
266 When an error occurs,
270 is set appropriately.
277 is not a valid file descriptor.
283 and the supplied file descriptor
285 is already registered with this epoll instance.
296 or the requested operation
298 is not supported by this interface.
301 An invalid event type was specified along with
321 flag has previously been applied to this
331 refers to an epoll instance.
335 refers to an epoll instance and this
337 operation would result in a circular loop of epoll instances
338 monitoring one another.
348 is not registered with this epoll instance.
351 There was insufficient memory to handle the requested
357 .I /proc/sys/fs/epoll/max_user_watches
358 was encountered while trying to register
359 .RB ( EPOLL_CTL_ADD )
360 a new file descriptor on an epoll instance.
370 This error can occur if
372 refers to, for example, a regular file or a directory.
375 was added to the kernel in version 2.6.
376 .\" To be precise: kernel 2.5.44.
377 .\" The interface should be finalized by Linux kernel 2.5.66.
381 Library support is provided in glibc starting with version 2.3.2.
385 interface supports all file descriptors that support
388 In kernel versions before 2.6.9, the
390 operation required a non-null pointer in
392 even though this argument is ignored.
395 can be specified as NULL
398 Applications that need to be portable to kernels before 2.6.9
399 should specify a non-null pointer in
406 but the caller does not have the
407 .BR CAP_BLOCK_SUSPEND
411 .IR "silently ignored" .
412 This unfortunate behavior is necessary because no validity
413 checks were performed on the
415 argument in the original implementation, and the addition of the
417 with a check that caused the call to fail if the caller did not have the
419 capability caused a breakage in at least one existing user-space
420 application that happened to randomly (and uselessly) specify this bit.
421 .\" commit a8159414d7e3af7233e7a5a82d1c5d85379bd75c (behavior change)
422 .\" https://lwn.net/Articles/520198/
423 A robust application should therefore double check that it has the
425 capability if attempting to use the
429 .BR epoll_create (2),