Debian Codegraph @

templates/man7/epoll.7.pot

raw
1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 #
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2026-06-05 06:23+0200\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <[email protected]>\n"
14 "Language: \n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
18
19 #. type: TH
20 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
21 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
22 #, no-wrap
23 msgid "epoll"
24 msgstr ""
25
26 #. type: TH
27 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
28 #: opensuse-tumbleweed
29 #, no-wrap
30 msgid "2026-02-08"
31 msgstr ""
32
33 #. type: TH
34 #: archlinux debian-unstable
35 #, no-wrap
36 msgid "Linux man-pages 6.18"
37 msgstr ""
38
39 #. type: SH
40 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
41 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
42 #, no-wrap
43 msgid "NAME"
44 msgstr ""
45
46 #. type: Plain text
47 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
48 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
49 msgid "epoll - I/O event notification facility"
50 msgstr ""
51
52 #. type: SH
53 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
54 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
55 #, no-wrap
56 msgid "SYNOPSIS"
57 msgstr ""
58
59 #. type: Plain text
60 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
61 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
62 #, no-wrap
63 msgid "B<#include E<lt>sys/epoll.hE<gt>>\n"
64 msgstr ""
65
66 #. type: SH
67 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
68 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
69 #, no-wrap
70 msgid "DESCRIPTION"
71 msgstr ""
72
73 #. type: Plain text
74 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
75 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
76 msgid ""
77 "The B<epoll> API performs a similar task to B<poll>(2): monitoring multiple "
78 "file descriptors to see if I/O is possible on any of them. The B<epoll> API "
79 "can be used either as an edge-triggered or a level-triggered interface and "
80 "scales well to large numbers of watched file descriptors."
81 msgstr ""
82
83 #. type: Plain text
84 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
85 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
86 msgid ""
87 "The central concept of the B<epoll> API is the B<epoll> I<instance>, an in-"
88 "kernel data structure which, from a user-space perspective, can be "
89 "considered as a container for two lists:"
90 msgstr ""
91
92 #. type: IP
93 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
94 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
95 #, no-wrap
96 msgid "\\[bu]"
97 msgstr ""
98
99 #. type: Plain text
100 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
101 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
102 msgid ""
103 "The I<interest> list (sometimes also called the B<epoll> set): the set of "
104 "file descriptors that the process has registered an interest in monitoring."
105 msgstr ""
106
107 #. type: Plain text
108 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
109 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
110 msgid ""
111 "The I<ready> list: the set of file descriptors that are \"ready\" for I/O. "
112 "The ready list is a subset of (or, more precisely, a set of references to) "
113 "the file descriptors in the interest list. The ready list is dynamically "
114 "populated by the kernel as a result of I/O activity on those file "
115 "descriptors."
116 msgstr ""
117
118 #. type: Plain text
119 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
120 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
121 msgid ""
122 "The following system calls are provided to create and manage an B<epoll> "
123 "instance:"
124 msgstr ""
125
126 #. type: Plain text
127 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
128 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
129 msgid ""
130 "B<epoll_create>(2) creates a new B<epoll> instance and returns a file "
131 "descriptor referring to that instance. (The more recent "
132 "B<epoll_create1>(2) extends the functionality of B<epoll_create>(2).)"
133 msgstr ""
134
135 #. type: Plain text
136 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
137 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
138 msgid ""
139 "Interest in particular file descriptors is then registered via "
140 "B<epoll_ctl>(2), which adds items to the interest list of the B<epoll> "
141 "instance."
142 msgstr ""
143
144 #. type: Plain text
145 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
146 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
147 msgid ""
148 "B<epoll_wait>(2) waits for I/O events, blocking the calling thread if no "
149 "events are currently available. (This system call can be thought of as "
150 "fetching items from the ready list of the B<epoll> instance.)"
151 msgstr ""
152
153 #. type: SS
154 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
155 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
156 #, no-wrap
157 msgid "Level-triggered and edge-triggered"
158 msgstr ""
159
160 #. type: Plain text
161 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
162 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
163 msgid ""
164 "The B<epoll> event distribution interface is able to behave both as edge-"
165 "triggered (ET) and as level-triggered (LT). The difference between the two "
166 "mechanisms can be described as follows. Suppose that this scenario happens:"
167 msgstr ""
168
169 #. type: IP
170 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
171 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
172 #, no-wrap
173 msgid "(1)"
174 msgstr ""
175
176 #. type: Plain text
177 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
178 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
179 msgid ""
180 "The file descriptor that represents the read side of a pipe (I<rfd>) is "
181 "registered on the B<epoll> instance."
182 msgstr ""
183
184 #. type: IP
185 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
186 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
187 #, no-wrap
188 msgid "(2)"
189 msgstr ""
190
191 #. type: Plain text
192 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
193 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
194 msgid "A pipe writer writes 2\\ kB of data on the write side of the pipe."
195 msgstr ""
196
197 #. type: IP
198 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
199 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
200 #, no-wrap
201 msgid "(3)"
202 msgstr ""
203
204 #. type: Plain text
205 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
206 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
207 msgid ""
208 "A call to B<epoll_wait>(2) is done that will return I<rfd> as a ready file "
209 "descriptor."
210 msgstr ""
211
212 #. type: IP
213 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
214 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
215 #, no-wrap
216 msgid "(4)"
217 msgstr ""
218
219 #. type: Plain text
220 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
221 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
222 msgid "The pipe reader reads 1\\ kB of data from I<rfd>."
223 msgstr ""
224
225 #. type: IP
226 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
227 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
228 #, no-wrap
229 msgid "(5)"
230 msgstr ""
231
232 #. type: Plain text
233 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
234 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
235 msgid "A call to B<epoll_wait>(2) is done."
236 msgstr ""
237
238 #. type: Plain text
239 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
240 #: opensuse-leap-16-1 opensuse-tumbleweed
241 msgid ""
242 "If the I<rfd> file descriptor has been added to the B<epoll> interface using "
243 "the B<EPOLLET> (edge-triggered) flag, the call to B<epoll_wait>(2) done in "
244 "step B<5> will probably hang despite the available data still present in the "
245 "file input buffer; meanwhile the remote peer might be expecting a response "
246 "based on the data it already sent. The reason for this is that edge-"
247 "triggered mode delivers events only when changes occur on the monitored file "
248 "descriptor, that is, an event will be generated upon each receipt of a chunk "
249 "of data. So, in step B<5> the caller might end up waiting for some data "
250 "that is already present inside the input buffer. In the above example, an "
251 "event on I<rfd> will be generated because of the write done in B<2> and the "
252 "event is consumed in B<3>. Since the read operation done in B<4> does not "
253 "consume the whole buffer data, the call to B<epoll_wait>(2) done in step "
254 "B<5> might block indefinitely."
255 msgstr ""
256
257 #. type: Plain text
258 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
259 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
260 msgid ""
261 "An application that employs the B<EPOLLET> flag should use nonblocking file "
262 "descriptors to avoid having a blocking read or write starve a task that is "
263 "handling multiple file descriptors. The suggested way to use B<epoll> as an "
264 "edge-triggered (B<EPOLLET>) interface is as follows:"
265 msgstr ""
266
267 #. type: Plain text
268 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
269 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
270 msgid "with nonblocking file descriptors; and"
271 msgstr ""
272
273 #. type: Plain text
274 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
275 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
276 msgid ""
277 "by waiting for an event only after B<read>(2) or B<write>(2) return "
278 "B<EAGAIN>."
279 msgstr ""
280
281 #. type: Plain text
282 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
283 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
284 msgid ""
285 "By contrast, when used as a level-triggered interface (the default, when "
286 "B<EPOLLET> is not specified), B<epoll> is simply a faster B<poll>(2), and "
287 "can be used wherever the latter is used since it shares the same semantics."
288 msgstr ""
289
290 #. type: Plain text
291 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
292 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
293 msgid ""
294 "Since even with edge-triggered B<epoll>, multiple events can be generated "
295 "upon receipt of multiple chunks of data, the caller has the option to "
296 "specify the B<EPOLLONESHOT> flag, to tell B<epoll> to disable the associated "
297 "file descriptor after the receipt of an event with B<epoll_wait>(2). When "
298 "the B<EPOLLONESHOT> flag is specified, it is the caller's responsibility to "
299 "rearm the file descriptor using B<epoll_ctl>(2) with B<EPOLL_CTL_MOD>."
300 msgstr ""
301
302 #. type: Plain text
303 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
304 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
305 msgid ""
306 "If multiple threads (or processes, if child processes have inherited the "
307 "B<epoll> file descriptor across B<fork>(2)) are blocked in "
308 "B<epoll_wait>(2) waiting on the same epoll file descriptor and a file "
309 "descriptor in the interest list that is marked for edge-triggered "
310 "(B<EPOLLET>) notification becomes ready, just one of the threads (or "
311 "processes) is awoken from B<epoll_wait>(2). This provides a useful "
312 "optimization for avoiding \"thundering herd\" wake-ups in some scenarios."
313 msgstr ""
314
315 #. type: SS
316 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
317 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
318 #, no-wrap
319 msgid "Interaction with autosleep"
320 msgstr ""
321
322 #. type: Plain text
323 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
324 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
325 msgid ""
326 "If the system is in B<autosleep> mode via I</sys/power/autosleep> and an "
327 "event happens which wakes the device from sleep, the device driver will keep "
328 "the device awake only until that event is queued. To keep the device awake "
329 "until the event has been processed, it is necessary to use the "
330 "B<epoll_ctl>(2) B<EPOLLWAKEUP> flag."
331 msgstr ""
332
333 #. type: Plain text
334 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
335 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
336 msgid ""
337 "When the B<EPOLLWAKEUP> flag is set in the B<events> field for a I<struct "
338 "epoll_event>, the system will be kept awake from the moment the event is "
339 "queued, through the B<epoll_wait>(2) call which returns the event until the "
340 "subsequent B<epoll_wait>(2) call. If the event should keep the system "
341 "awake beyond that time, then a separate I<wake_lock> should be taken before "
342 "the second B<epoll_wait>(2) call."
343 msgstr ""
344
345 #. type: SS
346 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
347 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
348 #, no-wrap
349 msgid "/proc interfaces"
350 msgstr ""
351
352 #. Following was added in Linux 2.6.28, but them removed in Linux 2.6.29
353 #. .TP
354 #. .IR /proc/sys/fs/epoll/max_user_instances " (since Linux 2.6.28)"
355 #. This specifies an upper limit on the number of epoll instances
356 #. that can be created per real user ID.
357 #. type: Plain text
358 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
359 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
360 msgid ""
361 "The following interfaces can be used to limit the amount of kernel memory "
362 "consumed by epoll:"
363 msgstr ""
364
365 #. type: TP
366 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
367 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
368 #, no-wrap
369 msgid "I</proc/sys/fs/epoll/max_user_watches> (since Linux 2.6.28)"
370 msgstr ""
371
372 #. Linux 2.6.29 (in Linux 2.6.28, the default was 1/32 of lowmem)
373 #. type: Plain text
374 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
375 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
376 msgid ""
377 "This specifies a limit on the total number of file descriptors that a user "
378 "can register across all epoll instances on the system. The limit is per "
379 "real user ID. Each registered file descriptor costs roughly 90 bytes on a "
380 "32-bit kernel, and roughly 160 bytes on a 64-bit kernel. Currently, the "
381 "default value for I<max_user_watches> is 1/25 (4%) of the available low "
382 "memory, divided by the registration cost in bytes."
383 msgstr ""
384
385 #. type: SS
386 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
387 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
388 #, no-wrap
389 msgid "Example for suggested usage"
390 msgstr ""
391
392 #. type: Plain text
393 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
394 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
395 msgid ""
396 "While the usage of B<epoll> when employed as a level-triggered interface "
397 "does have the same semantics as B<poll>(2), the edge-triggered usage "
398 "requires more clarification to avoid stalls in the application event loop. "
399 "In this example, listener is a nonblocking socket on which B<listen>(2) has "
400 "been called. The function I<do_use_fd()> uses the new ready file descriptor "
401 "until B<EAGAIN> is returned by either B<read>(2) or B<write>(2). An event-"
402 "driven state machine application should, after having received B<EAGAIN>, "
403 "record its current state so that at the next call to I<do_use_fd()> it will "
404 "continue to B<read>(2) or B<write>(2) from where it stopped before."
405 msgstr ""
406
407 #. type: Plain text
408 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
409 #: opensuse-tumbleweed
410 #, no-wrap
411 msgid ""
412 "#define MAX_EVENTS 10\n"
413 "struct epoll_event ev, events[MAX_EVENTS];\n"
414 "int listen_sock, conn_sock, nfds, epollfd;\n"
415 "\\&\n"
416 "/* Code to set up listening socket, \\[aq]listen_sock\\[aq],\n"
417 " (socket(), bind(), listen()) omitted. */\n"
418 "\\&\n"
419 "epollfd = epoll_create1(0);\n"
420 "if (epollfd == -1) {\n"
421 " perror(\"epoll_create1\");\n"
422 " exit(EXIT_FAILURE);\n"
423 "}\n"
424 "\\&\n"
425 "ev.events = EPOLLIN;\n"
426 "ev.data.fd = listen_sock;\n"
427 "if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == -1) {\n"
428 " perror(\"epoll_ctl: listen_sock\");\n"
429 " exit(EXIT_FAILURE);\n"
430 "}\n"
431 "\\&\n"
432 "for (;;) {\n"
433 " nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);\n"
434 " if (nfds == -1) {\n"
435 " perror(\"epoll_wait\");\n"
436 " exit(EXIT_FAILURE);\n"
437 " }\n"
438 "\\&\n"
439 " for (n = 0; n E<lt> nfds; ++n) {\n"
440 " if (events[n].data.fd == listen_sock) {\n"
441 " conn_sock = accept(listen_sock,\n"
442 " (struct sockaddr *) &addr, &addrlen);\n"
443 " if (conn_sock == -1) {\n"
444 " perror(\"accept\");\n"
445 " exit(EXIT_FAILURE);\n"
446 " }\n"
447 " setnonblocking(conn_sock);\n"
448 " ev.events = EPOLLIN | EPOLLET;\n"
449 " ev.data.fd = conn_sock;\n"
450 " if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock,\n"
451 " &ev) == -1) {\n"
452 " perror(\"epoll_ctl: conn_sock\");\n"
453 " exit(EXIT_FAILURE);\n"
454 " }\n"
455 " } else {\n"
456 " do_use_fd(events[n].data.fd);\n"
457 " }\n"
458 " }\n"
459 "}\n"
460 msgstr ""
461
462 #. type: Plain text
463 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
464 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
465 msgid ""
466 "When used as an edge-triggered interface, for performance reasons, it is "
467 "possible to add the file descriptor inside the B<epoll> interface "
468 "(B<EPOLL_CTL_ADD>) once by specifying (B<EPOLLIN>|B<EPOLLOUT>). This "
469 "allows you to avoid continuously switching between B<EPOLLIN> and "
470 "B<EPOLLOUT> calling B<epoll_ctl>(2) with B<EPOLL_CTL_MOD>."
471 msgstr ""
472
473 #. type: SS
474 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
475 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
476 #, no-wrap
477 msgid "Questions and answers"
478 msgstr ""
479
480 #. type: Plain text
481 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
482 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
483 msgid ""
484 "What is the key used to distinguish the file descriptors registered in an "
485 "interest list?"
486 msgstr ""
487
488 #. type: Plain text
489 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
490 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
491 msgid ""
492 "The key is the combination of the file descriptor number and the open file "
493 "description (also known as an \"open file handle\", the kernel's internal "
494 "representation of an open file)."
495 msgstr ""
496
497 #. type: Plain text
498 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
499 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
500 msgid ""
501 "What happens if you register the same file descriptor on an B<epoll> "
502 "instance twice?"
503 msgstr ""
504
505 #
506 #
507 #. But a file descriptor duplicated by fork(2) can't be added to the
508 #. set, because the [file *, fd] pair is already in the epoll set.
509 #. That is a somewhat ugly inconsistency. On the one hand, a child process
510 #. cannot add the duplicate file descriptor to the epoll set. (In every
511 #. other case that I can think of, file descriptors duplicated by fork have
512 #. similar semantics to file descriptors duplicated by dup() and friends.) On
513 #. the other hand, the very fact that the child has a duplicate of the
514 #. file descriptor means that even if the parent closes its file descriptor,
515 #. then epoll_wait() in the parent will continue to receive notifications for
516 #. that file descriptor because of the duplicated file descriptor in the child.
517 #. See http://thread.gmane.org/gmane.linux.kernel/596462/
518 #. "epoll design problems with common fork/exec patterns"
519 #. mtk, Feb 2008
520 #. type: Plain text
521 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
522 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
523 msgid ""
524 "You will probably get B<EEXIST>. However, it is possible to add a duplicate "
525 "(B<dup>(2), B<dup2>(2), B<fcntl>(2) B<F_DUPFD>) file descriptor to the "
526 "same B<epoll> instance. This can be a useful technique for filtering "
527 "events, if the duplicate file descriptors are registered with different "
528 "I<events> masks."
529 msgstr ""
530
531 #. type: Plain text
532 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
533 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
534 msgid ""
535 "Can two B<epoll> instances wait for the same file descriptor? If so, are "
536 "events reported to both B<epoll> file descriptors?"
537 msgstr ""
538
539 #. type: Plain text
540 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
541 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
542 msgid ""
543 "Yes, and events would be reported to both. However, careful programming may "
544 "be needed to do this correctly."
545 msgstr ""
546
547 #. type: Plain text
548 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
549 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
550 msgid "Is the B<epoll> file descriptor itself poll/epoll/selectable?"
551 msgstr ""
552
553 #. type: Plain text
554 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
555 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
556 msgid ""
557 "Yes. If an B<epoll> file descriptor has events waiting, then it will "
558 "indicate as being readable."
559 msgstr ""
560
561 #. type: Plain text
562 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
563 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
564 msgid ""
565 "What happens if one attempts to put an B<epoll> file descriptor into its own "
566 "file descriptor set?"
567 msgstr ""
568
569 #. type: Plain text
570 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
571 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
572 msgid ""
573 "The B<epoll_ctl>(2) call fails (B<EINVAL>). However, you can add an "
574 "B<epoll> file descriptor inside another B<epoll> file descriptor set."
575 msgstr ""
576
577 #. type: Plain text
578 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
579 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
580 msgid ""
581 "Can I send an B<epoll> file descriptor over a UNIX domain socket to another "
582 "process?"
583 msgstr ""
584
585 #. type: Plain text
586 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
587 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
588 msgid ""
589 "Yes, but it does not make sense to do this, since the receiving process "
590 "would not have copies of the file descriptors in the interest list."
591 msgstr ""
592
593 #. type: Plain text
594 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
595 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
596 msgid ""
597 "Will closing a file descriptor cause it to be removed from all B<epoll> "
598 "interest lists?"
599 msgstr ""
600
601 #. type: Plain text
602 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
603 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
604 msgid ""
605 "Yes, but be aware of the following point. A file descriptor is a reference "
606 "to an open file description (see B<open>(2)). Whenever a file descriptor is "
607 "duplicated via B<dup>(2), B<dup2>(2), B<fcntl>(2) B<F_DUPFD>, or "
608 "B<fork>(2), a new file descriptor referring to the same open file "
609 "description is created. An open file description continues to exist until "
610 "all file descriptors referring to it have been closed."
611 msgstr ""
612
613 #. type: Plain text
614 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
615 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
616 msgid ""
617 "A file descriptor is removed from an interest list only after all the file "
618 "descriptors referring to the underlying open file description have been "
619 "closed. This means that even after a file descriptor that is part of an "
620 "interest list has been closed, events may be reported for that file "
621 "descriptor if other file descriptors referring to the same underlying file "
622 "description remain open. To prevent this happening, the file descriptor "
623 "must be explicitly removed from the interest list (using B<epoll_ctl>(2) "
624 "B<EPOLL_CTL_DEL>) before it is duplicated. Alternatively, the application "
625 "must ensure that all file descriptors are closed (which may be difficult if "
626 "file descriptors were duplicated behind the scenes by library functions that "
627 "used B<dup>(2) or B<fork>(2))."
628 msgstr ""
629
630 #. type: Plain text
631 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
632 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
633 msgid ""
634 "If more than one event occurs between B<epoll_wait>(2) calls, are they "
635 "combined or reported separately?"
636 msgstr ""
637
638 #. type: Plain text
639 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
640 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
641 msgid "They will be combined."
642 msgstr ""
643
644 #. type: Plain text
645 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
646 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
647 msgid ""
648 "Does an operation on a file descriptor affect the already collected but not "
649 "yet reported events?"
650 msgstr ""
651
652 #. type: Plain text
653 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
654 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
655 msgid ""
656 "You can do two operations on an existing file descriptor. Remove would be "
657 "meaningless for this case. Modify will reread available I/O."
658 msgstr ""
659
660 #. type: Plain text
661 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
662 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
663 msgid ""
664 "Do I need to continuously read/write a file descriptor until B<EAGAIN> when "
665 "using the B<EPOLLET> flag (edge-triggered behavior)?"
666 msgstr ""
667
668 #. type: Plain text
669 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
670 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
671 msgid ""
672 "Receiving an event from B<epoll_wait>(2) should suggest to you that such "
673 "file descriptor is ready for the requested I/O operation. You must consider "
674 "it ready until the next (nonblocking) read/write yields B<EAGAIN>. When "
675 "and how you will use the file descriptor is entirely up to you."
676 msgstr ""
677
678 #. type: Plain text
679 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
680 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
681 msgid ""
682 "For packet/token-oriented files (e.g., datagram socket, terminal in "
683 "canonical mode), the only way to detect the end of the read/write I/O space "
684 "is to continue to read/write until B<EAGAIN>."
685 msgstr ""
686
687 #. type: Plain text
688 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
689 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
690 msgid ""
691 "For stream-oriented files (e.g., pipe, FIFO, stream socket), the condition "
692 "that the read/write I/O space is exhausted can also be detected by checking "
693 "the amount of data read from / written to the target file descriptor. For "
694 "example, if you call B<read>(2) by asking to read a certain amount of data "
695 "and B<read>(2) returns a lower number of bytes, you can be sure of having "
696 "exhausted the read I/O space for the file descriptor. The same is true when "
697 "writing using B<write>(2). (Avoid this latter technique if you cannot "
698 "guarantee that the monitored file descriptor always refers to a stream-"
699 "oriented file.)"
700 msgstr ""
701
702 #. type: SS
703 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
704 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
705 #, no-wrap
706 msgid "Possible pitfalls and ways to avoid them"
707 msgstr ""
708
709 #. type: Plain text
710 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
711 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
712 msgid "B<Starvation (edge-triggered)>"
713 msgstr ""
714
715 #. type: Plain text
716 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
717 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
718 msgid ""
719 "If there is a large amount of I/O space, it is possible that by trying to "
720 "drain it the other files will not get processed causing starvation. (This "
721 "problem is not specific to B<epoll>.)"
722 msgstr ""
723
724 #. type: Plain text
725 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
726 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
727 msgid ""
728 "The solution is to maintain a ready list and mark the file descriptor as "
729 "ready in its associated data structure, thereby allowing the application to "
730 "remember which files need to be processed but still round robin amongst all "
731 "the ready files. This also supports ignoring subsequent events you receive "
732 "for file descriptors that are already ready."
733 msgstr ""
734
735 #. type: Plain text
736 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
737 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
738 msgid "B<If using an event cache...>"
739 msgstr ""
740
741 #. type: Plain text
742 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
743 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
744 msgid ""
745 "If you use an event cache or store all the file descriptors returned from "
746 "B<epoll_wait>(2), then make sure to provide a way to mark its closure "
747 "dynamically (i.e., caused by a previous event's processing). Suppose you "
748 "receive 100 events from B<epoll_wait>(2), and in event #47 a condition "
749 "causes event #13 to be closed. If you remove the structure and B<close>(2) "
750 "the file descriptor for event #13, then your event cache might still say "
751 "there are events waiting for that file descriptor causing confusion."
752 msgstr ""
753
754 #. type: Plain text
755 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
756 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
757 msgid ""
758 "One solution for this is to call, during the processing of event 47, "
759 "B<epoll_ctl>(B<EPOLL_CTL_DEL>) to delete file descriptor 13 and "
760 "B<close>(2), then mark its associated data structure as removed and link it "
761 "to a cleanup list. If you find another event for file descriptor 13 in your "
762 "batch processing, you will discover the file descriptor had been previously "
763 "removed and there will be no confusion."
764 msgstr ""
765
766 #. type: SH
767 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
768 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
769 #, no-wrap
770 msgid "VERSIONS"
771 msgstr ""
772
773 #. type: Plain text
774 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
775 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
776 msgid ""
777 "Some other systems provide similar mechanisms; for example, FreeBSD has "
778 "I<kqueue>, and Solaris has I</dev/poll>."
779 msgstr ""
780
781 #. type: SH
782 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
783 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
784 #, no-wrap
785 msgid "STANDARDS"
786 msgstr ""
787
788 #. type: Plain text
789 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
790 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
791 msgid "Linux."
792 msgstr ""
793
794 #. type: SH
795 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
796 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
797 #, no-wrap
798 msgid "HISTORY"
799 msgstr ""
800
801 #. Its interface should be finalized in Linux 2.5.66.
802 #. type: Plain text
803 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
804 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
805 msgid "Linux 2.5.44. glibc 2.3.2."
806 msgstr ""
807
808 #. type: SH
809 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
810 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
811 #, no-wrap
812 msgid "NOTES"
813 msgstr ""
814
815 #. type: Plain text
816 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
817 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
818 msgid ""
819 "The set of file descriptors that is being monitored via an epoll file "
820 "descriptor can be viewed via the entry for the epoll file descriptor in the "
821 "process's I</proc/>pidI</fdinfo> directory. See B<proc>(5) for further "
822 "details."
823 msgstr ""
824
825 #. type: Plain text
826 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
827 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
828 msgid ""
829 "The B<kcmp>(2) B<KCMP_EPOLL_TFD> operation can be used to test whether a "
830 "file descriptor is present in an epoll instance."
831 msgstr ""
832
833 #. type: SH
834 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
835 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
836 #, no-wrap
837 msgid "SEE ALSO"
838 msgstr ""
839
840 #. type: Plain text
841 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
842 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
843 msgid ""
844 "B<epoll_create>(2), B<epoll_create1>(2), B<epoll_ctl>(2), B<epoll_wait>(2), "
845 "B<ioctl_eventpoll>(2), B<poll>(2), B<select>(2)"
846 msgstr ""
847
848 #. type: TH
849 #: debian-trixie
850 #, no-wrap
851 msgid "2024-06-12"
852 msgstr ""
853
854 #. type: TH
855 #: debian-trixie
856 #, no-wrap
857 msgid "Linux man-pages 6.9.1"
858 msgstr ""
859
860 #. type: Plain text
861 #: debian-trixie
862 msgid ""
863 "If the I<rfd> file descriptor has been added to the B<epoll> interface using "
864 "the B<EPOLLET> (edge-triggered) flag, the call to B<epoll_wait>(2) done in "
865 "step B<5> will probably hang despite the available data still present in the "
866 "file input buffer; meanwhile the remote peer might be expecting a response "
867 "based on the data it already sent. The reason for this is that edge-"
868 "triggered mode delivers events only when changes occur on the monitored file "
869 "descriptor. So, in step B<5> the caller might end up waiting for some data "
870 "that is already present inside the input buffer. In the above example, an "
871 "event on I<rfd> will be generated because of the write done in B<2> and the "
872 "event is consumed in B<3>. Since the read operation done in B<4> does not "
873 "consume the whole buffer data, the call to B<epoll_wait>(2) done in step "
874 "B<5> might block indefinitely."
875 msgstr ""
876
877 #. type: Plain text
878 #: debian-trixie fedora-44 fedora-rawhide
879 #, no-wrap
880 msgid ""
881 "#define MAX_EVENTS 10\n"
882 "struct epoll_event ev, events[MAX_EVENTS];\n"
883 "int listen_sock, conn_sock, nfds, epollfd;\n"
884 "\\&\n"
885 "/* Code to set up listening socket, \\[aq]listen_sock\\[aq],\n"
886 " (socket(), bind(), listen()) omitted. */\n"
887 "\\&\n"
888 "epollfd = epoll_create1(0);\n"
889 "if (epollfd == -1) {\n"
890 " perror(\"epoll_create1\");\n"
891 " exit(EXIT_FAILURE);\n"
892 "}\n"
893 "\\&\n"
894 "ev.events = EPOLLIN;\n"
895 "ev.data.fd = listen_sock;\n"
896 "if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == -1) {\n"
897 " perror(\"epoll_ctl: listen_sock\");\n"
898 " exit(EXIT_FAILURE);\n"
899 "}\n"
900 "\\&\n"
901 "for (;;) {\n"
902 " nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);\n"
903 " if (nfds == -1) {\n"
904 " perror(\"epoll_wait\");\n"
905 " exit(EXIT_FAILURE);\n"
906 " }\n"
907 "\\&\n"
908 " for (n = 0; n E<lt> nfds; ++n) {\n"
909 " if (events[n].data.fd == listen_sock) {\n"
910 " conn_sock = accept(listen_sock,\n"
911 " (struct sockaddr *) &addr, &addrlen);\n"
912 " if (conn_sock == -1) {\n"
913 " perror(\"accept\");\n"
914 " exit(EXIT_FAILURE);\n"
915 " }\n"
916 " setnonblocking(conn_sock);\n"
917 " ev.events = EPOLLIN | EPOLLET;\n"
918 " ev.data.fd = conn_sock;\n"
919 " if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock,\n"
920 " &ev) == -1) {\n"
921 " perror(\"epoll_ctl: conn_sock\");\n"
922 " exit(EXIT_FAILURE);\n"
923 " }\n"
924 " } else {\n"
925 " do_use_fd(events[n].data.fd);\n"
926 " }\n"
927 " }\n"
928 "}\n"
929 msgstr ""
930
931 #. type: TH
932 #: fedora-44 fedora-rawhide
933 #, no-wrap
934 msgid "2024-08-21"
935 msgstr ""
936
937 #. type: TH
938 #: fedora-44 fedora-rawhide
939 #, no-wrap
940 msgid "Linux man-pages 6.13"
941 msgstr ""
942
943 #. type: TH
944 #: mageia-cauldron
945 #, no-wrap
946 msgid "Linux man-pages 6.17"
947 msgstr ""
948
949 #. type: TH
950 #: opensuse-leap-16-1 opensuse-tumbleweed
951 #, no-wrap
952 msgid "Linux man-pages (unreleased)"
953 msgstr ""