2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (C) 2003 Davide Libenzi
|
|
|
|
.\"
|
epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, ioprio_set.2, signalfd.2, spu_create.2, spu_run.2, timerfd_create.2, charmap.5, locale.5, nscd.conf.5, epoll.7, spufs.7, ldconfig.8, nscd.8: s/GPLv2+_3_PARA_SW/GPLv2+_SW_3_PARA/
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:29:45 +00:00
|
|
|
.\" %%%LICENSE_START(GPLv2+_SW_3_PARA)
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" This program is free software; you can redistribute it and/or modify
|
|
|
|
.\" it under the terms of the GNU General Public License as published by
|
|
|
|
.\" the Free Software Foundation; either version 2 of the License, or
|
|
|
|
.\" (at your option) any later version.
|
|
|
|
.\"
|
|
|
|
.\" This program is distributed in the hope that it will be useful,
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
.\" GNU General Public License for more details.
|
|
|
|
.\"
|
epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, ioprio_set.2, signalfd.2, spu_create.2, spu_run.2, timerfd_create.2, epoll.7, spufs.7: Global fix: Update info in source comments on where to get a copy of the GPL
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:28:52 +00:00
|
|
|
.\" You should have received a copy of the GNU General Public
|
|
|
|
.\" License along with this manual; if not, see
|
|
|
|
.\" <http://www.gnu.org/licenses/>.
|
epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, fallocate.2, futex.2, getcpu.2, getitimer.2, ioctl_list.2, ioprio_set.2, migrate_pages.2, move_pages.2, pciconfig_read.2, sendfile.2, setns.2, signalfd.2, spu_create.2, spu_run.2, sysinfo.2, timerfd_create.2, backtrace.3, cmsg.3, error.3, getpt.3, getrpcent.3, getrpcport.3, getsubopt.3, offsetof.3, program_invocation_name.3, rpc.3, rpmatch.3, rtnetlink.3, xdr.3, cciss.4, hpsa.4, pts.4, charmap.5, dir_colors.5, elf.5, gai.conf.5, locale.5, nscd.conf.5, nss.5, resolv.conf.5, rpc.5, arp.7, cpuset.7, ddp.7, epoll.7, fifo.7, futex.7, icmp.7, ip.7, ipv6.7, mailaddr.7, netdevice.7, packet.7, raw.7, regex.7, rtnetlink.7, socket.7, spufs.7, tcp.7, udp.7, unix.7, x25.7, ldconfig.8, nscd.8: Global fix: s/END_LICENSE/LICENSE_END/
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-12 09:26:07 +00:00
|
|
|
.\" %%%LICENSE_END
|
2004-11-03 13:51:07 +00:00
|
|
|
.\"
|
|
|
|
.\" Davide Libenzi <davidel@xmailserver.org>
|
|
|
|
.\"
|
getent.1, iconv.1, ldd.1, locale.1, localedef.1, memusage.1, memusagestat.1, pldd.1, sprof.1, time.1, _syscall.2, accept.2, add_key.2, adjtimex.2, bind.2, bpf.2, capget.2, chown.2, chroot.2, clock_getres.2, clone.2, connect.2, copy_file_range.2, epoll_ctl.2, epoll_wait.2, eventfd.2, fanotify_init.2, fanotify_mark.2, fcntl.2, fsync.2, futex.2, getcpu.2, getdents.2, getgid.2, getgroups.2, getpid.2, gettid.2, gettimeofday.2, getuid.2, getxattr.2, inotify_add_watch.2, inotify_init.2, ioctl_fat.2, ioctl_ns.2, ioctl_userfaultfd.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, madvise.2, memfd_create.2, migrate_pages.2, mount.2, mprotect.2, mremap.2, msgctl.2, msgop.2, nfsservctl.2, open_by_handle_at.2, perf_event_open.2, pipe.2, pivot_root.2, pkey_alloc.2, poll.2, posix_fadvise.2, prctl.2, readahead.2, readdir.2, readlink.2, reboot.2, recvmmsg.2, removexattr.2, rename.2, request_key.2, s390_guarded_storage.2, s390_runtime_instr.2, s390_sthyi.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, seccomp.2, select.2, select_tut.2, semctl.2, sendmmsg.2, set_thread_area.2, setgid.2, setns.2, setuid.2, setxattr.2, shmctl.2, sigaction.2, signalfd.2, sigsuspend.2, socket.2, socketpair.2, spu_run.2, stat.2, statx.2, subpage_prot.2, syscalls.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, vmsplice.2, write.2, CPU_SET.3, __ppc_get_timebase.3, alloca.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bsd_signal.3, bstring.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, cmsg.3, confstr.3, ctermid.3, ctime.3, des_crypt.3, dl_iterate_phdr.3, dlinfo.3, dlsym.3, duplocale.3, end.3, endian.3, errno.3, exec.3, exit.3, ferror.3, fgetws.3, fmemopen.3, fnmatch.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getmntent.3, getnameinfo.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, isatty.3, iswblank.3, iswspace.3, lockf.3, makecontext.3, mallinfo.3, malloc.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_rwlockattr_setkind_np.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, putenv.3, qsort.3, rand.3, random.3, readdir.3, regex.3, resolver.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcmp.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strfry.3, strftime.3, string.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, system.3, termios.3, trunc.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, xcrypt.3, console_codes.4, dsp56k.4, full.4, initrd.4, lirc.4, loop.4, st.4, tty.4, vcs.4, charmap.5, core.5, host.conf.5, locale.5, proc.5, repertoiremap.5, resolv.conf.5, termcap.5, tmpfs.5, tzfile.5, aio.7, capabilities.7, cgroup_namespaces.7, cgroups.7, charsets.7, complex.7, epoll.7, fanotify.7, feature_test_macros.7, inotify.7, ip.7, locale.7, man-pages.7, man.7, namespaces.7, pid_namespaces.7, pkeys.7, pthreads.7, rtld-audit.7, sched.7, signal.7, sock_diag.7, socket.7, tcp.7, udp.7, unicode.7, user_namespaces.7, utf-8.7, zdump.8, zic.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-03-06 14:11:03 +00:00
|
|
|
.TH EPOLL 7 2019-03-06 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
epoll \- I/O event notification facility
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <sys/epoll.h>
|
|
|
|
.SH DESCRIPTION
|
2012-04-14 19:23:08 +00:00
|
|
|
The
|
|
|
|
.B epoll
|
|
|
|
API performs a similar task to
|
|
|
|
.BR poll (2):
|
|
|
|
monitoring multiple file descriptors to see if I/O is possible on any of them.
|
|
|
|
The
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2012-04-14 19:23:08 +00:00
|
|
|
API can be used either as an edge-triggered or a level-triggered
|
2007-06-14 21:11:22 +00:00
|
|
|
interface and scales well to large numbers of watched file descriptors.
|
2018-06-22 07:30:02 +00:00
|
|
|
.PP
|
2018-06-22 07:45:04 +00:00
|
|
|
The central concept of the
|
|
|
|
.B epoll
|
|
|
|
API is the
|
|
|
|
.B epoll
|
|
|
|
.IR instance ,
|
|
|
|
an in-kernel data structure which, from a user-space perspective,
|
|
|
|
can be considered as a container for two lists:
|
2020-02-19 08:21:45 +00:00
|
|
|
.IP \(bu 2
|
2018-06-22 07:45:04 +00:00
|
|
|
The
|
|
|
|
.I interest
|
|
|
|
list (sometimes also called the
|
|
|
|
.B epoll
|
|
|
|
set): the set of file descriptors that the process has registered
|
|
|
|
an interest in monitoring.
|
2020-02-19 08:21:45 +00:00
|
|
|
.IP \(bu
|
2018-06-22 07:45:04 +00:00
|
|
|
The
|
|
|
|
.I ready
|
|
|
|
list: the set of file descriptors that are "ready" for I/O.
|
|
|
|
The ready list is a subset of
|
|
|
|
(or, more precisely, a set of references to)
|
2020-02-19 08:10:00 +00:00
|
|
|
the file descriptors in the interest list.
|
|
|
|
The ready list is dynamically populated
|
2018-06-22 07:45:04 +00:00
|
|
|
by the kernel as a result of I/O activity on those file descriptors.
|
|
|
|
.PP
|
2008-10-10 14:00:48 +00:00
|
|
|
The following system calls are provided to
|
2009-01-16 09:23:49 +00:00
|
|
|
create and manage an
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2009-01-16 09:23:49 +00:00
|
|
|
instance:
|
2020-02-19 08:21:45 +00:00
|
|
|
.IP \(bu 2
|
2012-04-14 19:23:08 +00:00
|
|
|
.BR epoll_create (2)
|
2017-03-17 05:53:14 +00:00
|
|
|
creates a new
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2012-04-14 19:23:08 +00:00
|
|
|
instance and returns a file descriptor referring to that instance.
|
2008-10-10 14:00:48 +00:00
|
|
|
(The more recent
|
|
|
|
.BR epoll_create1 (2)
|
|
|
|
extends the functionality of
|
|
|
|
.BR epoll_create (2).)
|
2020-02-19 08:21:45 +00:00
|
|
|
.IP \(bu
|
2009-01-16 09:23:49 +00:00
|
|
|
Interest in particular file descriptors is then registered via
|
2018-06-22 07:45:04 +00:00
|
|
|
.BR epoll_ctl (2),
|
|
|
|
which adds items to the interest list of the
|
2018-06-22 07:41:16 +00:00
|
|
|
.B epoll
|
2018-06-22 07:45:04 +00:00
|
|
|
instance.
|
2020-02-19 08:21:45 +00:00
|
|
|
.IP \(bu
|
2012-04-14 19:23:08 +00:00
|
|
|
.BR epoll_wait (2)
|
|
|
|
waits for I/O events,
|
|
|
|
blocking the calling thread if no events are currently available.
|
2018-06-22 07:45:04 +00:00
|
|
|
(This system call can be thought of as fetching items from
|
|
|
|
the ready list of the
|
|
|
|
.B epoll
|
|
|
|
instance.)
|
|
|
|
.\"
|
intro.1, time.1, _syscall.2, accept.2, brk.2, capget.2, faccessat.2, futimesat.2, gethostname.2, intro.2, ioprio_set.2, kill.2, madvise.2, mlock.2, mount.2, msgget.2, perf_event_open.2, poll.2, readv.2, sched_rr_get_interval.2, sched_setscheduler.2, select.2, select_tut.2, shmget.2, stat.2, timer_create.2, ustat.2, vfork.2, wait.2, alloca.3, atexit.3, catopen.3, crypt.3, dbopen.3, fenv.3, fopen.3, getaddrinfo_a.3, gethostbyname.3, getutent.3, intro.3, login.3, mallopt.3, queue.3, regex.3, sigpause.3, sigsetops.3, stdio.3, strftime.3, strptime.3, sysconf.3, ttyslot.3, undocumented.3, cciss.4, console_codes.4, hpsa.4, initrd.4, intro.4, rtc.4, st.4, tty_ioctl.4, wavelan.4, acct.5, charmap.5, dir_colors.5, hosts.5, intro.5, termcap.5, utmp.5, intro.6, armscii-8.7, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, ddp.7, epoll.7, glob.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, man-pages.7, man.7, math_error.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, pthreads.7, raw.7, rtnetlink.7, signal.7, socket.7, spufs.7, svipc.7, tcp.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, intro.8: Global fix: use consistent capitalization in .SS headings
Capitalization in .SS sections across pages (and sometimes even
within a single page) is wildly inconsistent. Make it consistent.
Capitalize first word in heading, but otherwise use lower case,
except where English usage (e.g., proper nouns) or programming
language requirements (e.g., identifier names) dictate otherwise.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 14:08:38 +00:00
|
|
|
.SS Level-triggered and edge-triggered
|
2004-11-03 13:51:07 +00:00
|
|
|
The
|
|
|
|
.B epoll
|
2007-06-14 21:11:22 +00:00
|
|
|
event distribution interface is able to behave both as edge-triggered
|
2009-01-16 09:23:49 +00:00
|
|
|
(ET) and as level-triggered (LT).
|
2007-06-16 05:58:39 +00:00
|
|
|
The difference between the two mechanisms
|
|
|
|
can be described as follows.
|
2007-04-12 22:42:49 +00:00
|
|
|
Suppose that
|
2008-02-26 13:29:53 +00:00
|
|
|
this scenario happens:
|
2007-06-16 05:58:39 +00:00
|
|
|
.IP 1. 3
|
2007-06-14 21:11:22 +00:00
|
|
|
The file descriptor that represents the read side of a pipe
|
|
|
|
.RI ( rfd )
|
2009-01-16 09:23:49 +00:00
|
|
|
is registered on the
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2009-01-16 09:23:49 +00:00
|
|
|
instance.
|
2007-06-16 05:58:39 +00:00
|
|
|
.IP 2.
|
add_key.2, alloc_hugepages.2, execve.2, fanotify_init.2, getrlimit.2, listxattr.2, mmap.2, shmget.2, malloc.3, random.4, st.4, bootparam.7, epoll.7, keyrings.7, pipe.7, xattr.7: Use non-breaking space for measurement units
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 10:28:20 +00:00
|
|
|
A pipe writer writes 2\ kB of data on the write side of the pipe.
|
2007-06-16 05:58:39 +00:00
|
|
|
.IP 3.
|
2004-11-03 13:51:07 +00:00
|
|
|
A call to
|
|
|
|
.BR epoll_wait (2)
|
|
|
|
is done that will return
|
2007-06-14 21:11:22 +00:00
|
|
|
.I rfd
|
|
|
|
as a ready file descriptor.
|
2007-06-16 05:58:39 +00:00
|
|
|
.IP 4.
|
add_key.2, alloc_hugepages.2, execve.2, fanotify_init.2, getrlimit.2, listxattr.2, mmap.2, shmget.2, malloc.3, random.4, st.4, bootparam.7, epoll.7, keyrings.7, pipe.7, xattr.7: Use non-breaking space for measurement units
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 10:28:20 +00:00
|
|
|
The pipe reader reads 1\ kB of data from
|
2007-06-14 21:11:22 +00:00
|
|
|
.IR rfd .
|
2007-06-16 05:58:39 +00:00
|
|
|
.IP 5.
|
2004-11-03 13:51:07 +00:00
|
|
|
A call to
|
|
|
|
.BR epoll_wait (2)
|
|
|
|
is done.
|
|
|
|
.PP
|
|
|
|
If the
|
2007-06-14 21:11:22 +00:00
|
|
|
.I rfd
|
2004-11-03 13:51:07 +00:00
|
|
|
file descriptor has been added to the
|
|
|
|
.B epoll
|
|
|
|
interface using the
|
|
|
|
.B EPOLLET
|
2008-02-26 12:44:38 +00:00
|
|
|
(edge-triggered)
|
2004-11-03 13:51:07 +00:00
|
|
|
flag, the call to
|
|
|
|
.BR epoll_wait (2)
|
2007-06-21 22:55:04 +00:00
|
|
|
done in step
|
2004-11-03 13:51:07 +00:00
|
|
|
.B 5
|
2007-06-14 21:11:22 +00:00
|
|
|
will probably hang despite the available data still present in the file
|
|
|
|
input buffer;
|
|
|
|
meanwhile the remote peer might be expecting a response based on the
|
2007-04-12 22:42:49 +00:00
|
|
|
data it already sent.
|
intro.1, _syscall.2, access.2, arch_prctl.2, cacheflush.2, chown.2, clock_getres.2, clone.2, create_module.2, fcntl.2, flock.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getpriority.2, getrlimit.2, getrusage.2, ioprio_set.2, kexec_load.2, madvise.2, mbind.2, migrate_pages.2, mknod.2, mmap.2, mount.2, move_pages.2, mprotect.2, open.2, pause.2, pciconfig_read.2, perf_event_open.2, prctl.2, ptrace.2, query_module.2, read.2, reboot.2, recv.2, s390_runtime_instr.2, sched_setscheduler.2, select_tut.2, send.2, set_mempolicy.2, setfsgid.2, setfsuid.2, sigaction.2, spu_create.2, spu_run.2, stime.2, swapon.2, syslog.2, timer_create.2, timer_getoverrun.2, times.2, tkill.2, umount.2, unimplemented.2, ustat.2, vm86.2, wait.2, abs.3, aio_read.3, aio_write.3, bsd_signal.3, catgets.3, clearenv.3, cmsg.3, dbopen.3, dirfd.3, dlopen.3, exec.3, fenv.3, ferror.3, fmemopen.3, fnmatch.3, fopen.3, futimes.3, getaddrinfo.3, getifaddrs.3, getipnodebyname.3, hsearch.3, if_nameindex.3, inet_pton.3, mblen.3, mbrlen.3, mbsrtowcs.3, mbtowc.3, mcheck.3, memfrob.3, mq_notify.3, netlink.3, posix_memalign.3, printf.3, pthread_attr_setscope.3, pthread_cleanup_push.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setcancelstate.3, pthread_setconcurrency.3, raise.3, resolver.3, rpc.3, rtime.3, rtnetlink.3, scanf.3, setbuf.3, setnetgrent.3, shm_open.3, sigpause.3, sigset.3, sigwait.3, sockatmark.3, strcasecmp.3, strcmp.3, strdup.3, strftime.3, strptime.3, strsignal.3, strverscmp.3, sysv_signal.3, termios.3, wcrtomb.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wctomb.3, wprintf.3, console_codes.4, cpuid.4, msr.4, rtc.4, sk98lin.4, st.4, tty.4, charmap.5, core.5, elf.5, hosts.equiv.5, proc.5, resolv.conf.5, services.5, slabinfo.5, arp.7, bootparam.7, capabilities.7, charsets.7, cpuset.7, ddp.7, epoll.7, feature_test_macros.7, futex.7, hier.7, icmp.7, inotify.7, ip.7, ipv6.7, man-pages.7, mdoc.7, mdoc.samples.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, posixoptions.7, pthreads.7, raw.7, rtld-audit.7, rtnetlink.7, sem_overview.7, sigevent.7, socket.7, spufs.7, tcp.7, udp.7, unicode.7, uri.7, utf-8.7, intro.8, ldconfig.8, sync.8: Global fix: fix placement of word "only"
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-31 08:53:00 +00:00
|
|
|
The reason for this is that edge-triggered mode
|
|
|
|
delivers events only when changes occur on the monitored file descriptor.
|
2004-11-03 13:51:07 +00:00
|
|
|
So, in step
|
|
|
|
.B 5
|
|
|
|
the caller might end up waiting for some data that is already present inside
|
2007-04-12 22:42:49 +00:00
|
|
|
the input buffer.
|
|
|
|
In the above example, an event on
|
2007-06-14 21:11:22 +00:00
|
|
|
.I rfd
|
2004-11-03 13:51:07 +00:00
|
|
|
will be generated because of the write done in
|
2007-09-20 16:26:31 +00:00
|
|
|
.B 2
|
2005-10-28 17:48:03 +00:00
|
|
|
and the event is consumed in
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR 3 .
|
|
|
|
Since the read operation done in
|
|
|
|
.B 4
|
|
|
|
does not consume the whole buffer data, the call to
|
|
|
|
.BR epoll_wait (2)
|
|
|
|
done in step
|
|
|
|
.B 5
|
2007-06-14 21:11:22 +00:00
|
|
|
might block indefinitely.
|
environ.7, epoll.7, feature_test_macros.7, futex.7, ip.7, ipv6.7, locale.7, man-pages.7, man.7, math_error.7, netdevice.7, netlink.7, packet.7, raw.7, rtld-audit.7, rtnetlink.7, sock_diag.7, socket.7, tcp.7, udp.7, udplite.7, unix.7, uri.7, vdso.7: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 01:01:48 +00:00
|
|
|
.PP
|
2007-06-14 21:11:22 +00:00
|
|
|
An application that employs the
|
2004-11-03 13:51:07 +00:00
|
|
|
.B EPOLLET
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
flag should use nonblocking file descriptors to avoid having a blocking
|
2007-06-14 21:11:22 +00:00
|
|
|
read or write starve a task that is handling multiple file descriptors.
|
2004-11-03 13:51:07 +00:00
|
|
|
The suggested way to use
|
|
|
|
.B epoll
|
2007-06-14 21:11:22 +00:00
|
|
|
as an edge-triggered
|
2005-10-28 17:48:03 +00:00
|
|
|
.RB ( EPOLLET )
|
2007-06-14 21:11:22 +00:00
|
|
|
interface is as follows:
|
2020-02-19 08:24:58 +00:00
|
|
|
.IP a) 3
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
with nonblocking file descriptors; and
|
2020-02-19 08:24:58 +00:00
|
|
|
.IP b)
|
2007-06-16 05:58:39 +00:00
|
|
|
by waiting for an event only after
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR read (2)
|
2007-04-12 22:42:49 +00:00
|
|
|
or
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR write (2)
|
2007-06-22 20:40:07 +00:00
|
|
|
return
|
|
|
|
.BR EAGAIN .
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2008-02-26 12:44:38 +00:00
|
|
|
By contrast, when used as a level-triggered interface
|
|
|
|
(the default, when
|
|
|
|
.B EPOLLET
|
|
|
|
is not specified),
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2007-09-17 17:02:45 +00:00
|
|
|
is simply a faster
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR poll (2),
|
|
|
|
and can be used wherever the latter is used since it shares the
|
2007-04-12 22:42:49 +00:00
|
|
|
same semantics.
|
environ.7, epoll.7, feature_test_macros.7, futex.7, ip.7, ipv6.7, locale.7, man-pages.7, man.7, math_error.7, netdevice.7, netlink.7, packet.7, raw.7, rtld-audit.7, rtnetlink.7, sock_diag.7, socket.7, tcp.7, udp.7, udplite.7, unix.7, uri.7, vdso.7: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 01:01:48 +00:00
|
|
|
.PP
|
2009-01-16 09:23:49 +00:00
|
|
|
Since even with edge-triggered
|
|
|
|
.BR epoll ,
|
2007-06-14 21:11:22 +00:00
|
|
|
multiple events can be generated upon receipt of multiple chunks of data,
|
2004-11-03 13:51:07 +00:00
|
|
|
the caller has the option to specify the
|
|
|
|
.B EPOLLONESHOT
|
|
|
|
flag, to tell
|
|
|
|
.B epoll
|
2006-05-29 01:20:08 +00:00
|
|
|
to disable the associated file descriptor after the receipt of an event with
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_wait (2).
|
|
|
|
When the
|
|
|
|
.B EPOLLONESHOT
|
2007-04-12 22:42:49 +00:00
|
|
|
flag is specified,
|
2007-06-14 21:11:22 +00:00
|
|
|
it is the caller's responsibility to rearm the file descriptor using
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_ctl (2)
|
|
|
|
with
|
|
|
|
.BR EPOLL_CTL_MOD .
|
2018-06-22 08:12:39 +00:00
|
|
|
.PP
|
|
|
|
If multiple threads
|
|
|
|
(or processes, if child processes have inherited the
|
|
|
|
.B epoll
|
|
|
|
file descriptor across
|
|
|
|
.BR fork (2))
|
|
|
|
are blocked in
|
|
|
|
.BR epoll_wait (2)
|
2020-01-21 19:20:04 +00:00
|
|
|
waiting on the same epoll file descriptor and a file descriptor
|
2018-06-22 08:12:39 +00:00
|
|
|
in the interest list that is marked for edge-triggered
|
|
|
|
.RB ( EPOLLET )
|
|
|
|
notification becomes ready,
|
|
|
|
just one of the threads (or processes) is awoken from
|
|
|
|
.BR epoll_wait (2).
|
|
|
|
This provides a useful optimization for avoiding "thundering herd" wake-ups
|
|
|
|
in some scenarios.
|
|
|
|
.\"
|
2014-07-07 05:32:49 +00:00
|
|
|
.SS Interaction with autosleep
|
|
|
|
If the system is in
|
|
|
|
.B autosleep
|
|
|
|
mode via
|
|
|
|
.I /sys/power/autosleep
|
|
|
|
and an event happens which wakes the device from sleep, the device
|
2015-01-28 09:37:06 +00:00
|
|
|
driver will keep the device awake only until that event is queued.
|
2014-07-07 05:39:41 +00:00
|
|
|
To keep the device awake until the event has been processed,
|
|
|
|
it is necessary to use the
|
arch_prctl.2, execveat.2, fanotify_mark.2, fcntl.2, fork.2, madvise.2, mknod.2, mmap.2, modify_ldt.2, mount.2, open.2, prctl.2, ptrace.2, restart_syscall.2, seccomp.2, semop.2, set_thread_area.2, symlink.2, umount.2, unlink.2, error.3, getnetent.3, getprotoent.3, getservent.3, getutent.3, glob.3, login.3, setjmp.3, setnetgrent.3, wordexp.3, epoll.7: Remove section number from page self reference
Fix places where pages refer to the function that they describe
and include a section number in that reference. Such references
cause some HTML-rendering tools to create self-references in the
page.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-08-07 16:40:35 +00:00
|
|
|
.BR epoll_ctl (2)
|
2014-07-07 05:32:49 +00:00
|
|
|
.B EPOLLWAKEUP
|
|
|
|
flag.
|
environ.7, epoll.7, feature_test_macros.7, futex.7, ip.7, ipv6.7, locale.7, man-pages.7, man.7, math_error.7, netdevice.7, netlink.7, packet.7, raw.7, rtld-audit.7, rtnetlink.7, sock_diag.7, socket.7, tcp.7, udp.7, udplite.7, unix.7, uri.7, vdso.7: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 01:01:48 +00:00
|
|
|
.PP
|
2014-07-07 05:39:41 +00:00
|
|
|
When the
|
|
|
|
.B EPOLLWAKEUP
|
|
|
|
flag is set in the
|
2014-07-07 05:32:49 +00:00
|
|
|
.B events
|
|
|
|
field for a
|
2014-07-07 05:39:41 +00:00
|
|
|
.IR "struct epoll_event" ,
|
|
|
|
the system will be kept awake from the moment the event is queued,
|
2014-07-07 05:32:49 +00:00
|
|
|
through the
|
2014-07-07 05:39:41 +00:00
|
|
|
.BR epoll_wait (2)
|
2014-07-07 05:32:49 +00:00
|
|
|
call which returns the event until the subsequent
|
2014-07-07 05:39:41 +00:00
|
|
|
.BR epoll_wait (2)
|
|
|
|
call.
|
|
|
|
If the event should keep the system awake beyond that time,
|
|
|
|
then a separate
|
2014-07-07 05:32:49 +00:00
|
|
|
.I wake_lock
|
|
|
|
should be taken before the second
|
2014-07-07 05:39:41 +00:00
|
|
|
.BR epoll_wait (2)
|
2014-07-07 05:32:49 +00:00
|
|
|
call.
|
2009-01-16 08:34:35 +00:00
|
|
|
.SS /proc interfaces
|
|
|
|
The following interfaces can be used to limit the amount of
|
|
|
|
kernel memory consumed by epoll:
|
2009-01-31 19:23:38 +00:00
|
|
|
.\" Following was added in 2.6.28, but them removed in 2.6.29
|
2009-02-09 02:12:23 +00:00
|
|
|
.\" .TP
|
2009-01-31 19:23:38 +00:00
|
|
|
.\" .IR /proc/sys/fs/epoll/max_user_instances " (since Linux 2.6.28)"
|
|
|
|
.\" This specifies an upper limit on the number of epoll instances
|
|
|
|
.\" that can be created per real user ID.
|
2009-01-16 08:34:35 +00:00
|
|
|
.TP
|
|
|
|
.IR /proc/sys/fs/epoll/max_user_watches " (since Linux 2.6.28)"
|
|
|
|
This specifies a limit on the total number of
|
|
|
|
file descriptors that a user can register across
|
|
|
|
all epoll instances on the system.
|
|
|
|
The limit is per real user ID.
|
|
|
|
Each registered file descriptor costs roughly 90 bytes on a 32-bit kernel,
|
|
|
|
and roughly 160 bytes on a 64-bit kernel.
|
|
|
|
Currently,
|
2009-01-31 19:23:38 +00:00
|
|
|
.\" 2.6.29 (in 2.6.28, the default was 1/32 of lowmem)
|
2009-01-16 08:34:35 +00:00
|
|
|
the default value for
|
|
|
|
.I max_user_watches
|
2009-01-31 19:23:38 +00:00
|
|
|
is 1/25 (4%) of the available low memory,
|
2009-01-16 08:34:35 +00:00
|
|
|
divided by the registration cost in bytes.
|
intro.1, time.1, _syscall.2, accept.2, brk.2, capget.2, faccessat.2, futimesat.2, gethostname.2, intro.2, ioprio_set.2, kill.2, madvise.2, mlock.2, mount.2, msgget.2, perf_event_open.2, poll.2, readv.2, sched_rr_get_interval.2, sched_setscheduler.2, select.2, select_tut.2, shmget.2, stat.2, timer_create.2, ustat.2, vfork.2, wait.2, alloca.3, atexit.3, catopen.3, crypt.3, dbopen.3, fenv.3, fopen.3, getaddrinfo_a.3, gethostbyname.3, getutent.3, intro.3, login.3, mallopt.3, queue.3, regex.3, sigpause.3, sigsetops.3, stdio.3, strftime.3, strptime.3, sysconf.3, ttyslot.3, undocumented.3, cciss.4, console_codes.4, hpsa.4, initrd.4, intro.4, rtc.4, st.4, tty_ioctl.4, wavelan.4, acct.5, charmap.5, dir_colors.5, hosts.5, intro.5, termcap.5, utmp.5, intro.6, armscii-8.7, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, ddp.7, epoll.7, glob.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, man-pages.7, man.7, math_error.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, pthreads.7, raw.7, rtnetlink.7, signal.7, socket.7, spufs.7, svipc.7, tcp.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, intro.8: Global fix: use consistent capitalization in .SS headings
Capitalization in .SS sections across pages (and sometimes even
within a single page) is wildly inconsistent. Make it consistent.
Capitalize first word in heading, but otherwise use lower case,
except where English usage (e.g., proper nouns) or programming
language requirements (e.g., identifier names) dictate otherwise.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 14:08:38 +00:00
|
|
|
.SS Example for suggested usage
|
2004-11-03 13:51:07 +00:00
|
|
|
While the usage of
|
|
|
|
.B epoll
|
2007-06-14 21:11:22 +00:00
|
|
|
when employed as a level-triggered interface does have the same
|
|
|
|
semantics as
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR poll (2),
|
2007-06-14 21:11:22 +00:00
|
|
|
the edge-triggered usage requires more clarification to avoid stalls
|
2007-04-12 22:42:49 +00:00
|
|
|
in the application event loop.
|
|
|
|
In this example, listener is a
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
nonblocking socket on which
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR listen (2)
|
2007-04-12 22:42:49 +00:00
|
|
|
has been called.
|
2008-02-29 16:28:54 +00:00
|
|
|
The function
|
|
|
|
.I do_use_fd()
|
|
|
|
uses the new ready file descriptor until
|
2007-06-22 20:40:07 +00:00
|
|
|
.B EAGAIN
|
|
|
|
is returned by either
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR read (2)
|
|
|
|
or
|
|
|
|
.BR write (2).
|
2007-06-14 21:11:22 +00:00
|
|
|
An event-driven state machine application should, after having received
|
2007-06-22 20:40:07 +00:00
|
|
|
.BR EAGAIN ,
|
2008-02-29 16:28:54 +00:00
|
|
|
record its current state so that at the next call to
|
|
|
|
.I do_use_fd()
|
2004-11-03 13:51:07 +00:00
|
|
|
it will continue to
|
|
|
|
.BR read (2)
|
|
|
|
or
|
|
|
|
.BR write (2)
|
2007-04-12 22:42:49 +00:00
|
|
|
from where it stopped before.
|
environ.7, epoll.7, feature_test_macros.7, futex.7, ip.7, ipv6.7, locale.7, man-pages.7, man.7, math_error.7, netdevice.7, netlink.7, packet.7, raw.7, rtld-audit.7, rtnetlink.7, sock_diag.7, socket.7, tcp.7, udp.7, udplite.7, unix.7, uri.7, vdso.7: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 01:01:48 +00:00
|
|
|
.PP
|
2008-02-28 16:04:59 +00:00
|
|
|
.in +4n
|
_syscall.2, capget.2, ioprio_set.2, semop.2, send.2, ctime.3, dysize.3, fenv.3, fmtmsg.3, ftok.3, ftw.3, getaddrinfo.3, getgrent_r.3, gethostbyname.3, getopt.3, getpw.3, getpwent_r.3, getsubopt.3, getutent.3, glob.3, if_nameindex.3, inet.3, lseek64.3, malloc_hook.3, mbrtowc.3, mkstemp.3, mq_receive.3, mq_send.3, posix_spawn.3, putgrent.3, putpwent.3, qsort.3, raise.3, rand.3, rtime.3, setaliasent.3, setbuf.3, shm_open.3, significand.3, sigqueue.3, statvfs.3, strfromd.3, strptime.3, strtol.3, strtoul.3, termios.3, tgamma.3, timeradd.3, tsearch.3, tzset.3, updwtmp.3, usleep.3, wcstok.3, console_codes.4, hd.4, hpsa.4, mem.4, null.4, ram.4, sd.4, ttyS.4, filesystems.5, group.5, passwd.5, shells.5, termcap.5, ttytype.5, tzfile.5, utmp.5, ascii.7, bootparam.7, complex.7, cpuset.7, epoll.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 21:40:17 +00:00
|
|
|
.EX
|
2008-11-01 19:30:05 +00:00
|
|
|
#define MAX_EVENTS 10
|
|
|
|
struct epoll_event ev, events[MAX_EVENTS];
|
|
|
|
int listen_sock, conn_sock, nfds, epollfd;
|
|
|
|
|
2015-01-06 14:35:41 +00:00
|
|
|
/* Code to set up listening socket, \(aqlisten_sock\(aq,
|
|
|
|
(socket(), bind(), listen()) omitted */
|
2008-11-01 19:30:05 +00:00
|
|
|
|
2015-01-06 14:31:39 +00:00
|
|
|
epollfd = epoll_create1(0);
|
2008-11-01 19:30:05 +00:00
|
|
|
if (epollfd == \-1) {
|
2015-01-06 14:31:39 +00:00
|
|
|
perror("epoll_create1");
|
2008-11-01 19:30:05 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2009-01-23 22:51:53 +00:00
|
|
|
ev.events = EPOLLIN;
|
2008-11-01 19:30:05 +00:00
|
|
|
ev.data.fd = listen_sock;
|
|
|
|
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == \-1) {
|
|
|
|
perror("epoll_ctl: listen_sock");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2007-06-20 20:52:14 +00:00
|
|
|
for (;;) {
|
2008-11-01 19:30:05 +00:00
|
|
|
nfds = epoll_wait(epollfd, events, MAX_EVENTS, \-1);
|
2008-11-04 15:56:17 +00:00
|
|
|
if (nfds == \-1) {
|
2015-06-04 10:23:45 +00:00
|
|
|
perror("epoll_wait");
|
2008-11-04 15:56:17 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2004-11-03 13:51:07 +00:00
|
|
|
|
2007-04-05 12:36:57 +00:00
|
|
|
for (n = 0; n < nfds; ++n) {
|
2008-11-01 19:30:05 +00:00
|
|
|
if (events[n].data.fd == listen_sock) {
|
|
|
|
conn_sock = accept(listen_sock,
|
accept.2, bind.2, connect.2, getpeername.2, getsockname.2, recv.2, recvmmsg.2, select_tut.2, send.2, sendmmsg.2, getaddrinfo.3, getnameinfo.3, epoll.7, unix.7: Use consistent argument/variable names for socket addresses and lengths
As noted by Carlos, there's quite a bit of inconsistency across
pages. Use 'addr' and 'addrlen' consistently in variables and
function arguments.
Cowritten-by: Carlos O'Donell <carlos@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-02-03 12:10:04 +00:00
|
|
|
(struct sockaddr *) &addr, &addrlen);
|
2008-11-01 19:30:05 +00:00
|
|
|
if (conn_sock == \-1) {
|
2004-11-03 13:51:07 +00:00
|
|
|
perror("accept");
|
2008-11-04 15:53:36 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2008-11-01 19:30:05 +00:00
|
|
|
setnonblocking(conn_sock);
|
2004-11-03 13:51:07 +00:00
|
|
|
ev.events = EPOLLIN | EPOLLET;
|
2008-11-01 19:30:05 +00:00
|
|
|
ev.data.fd = conn_sock;
|
|
|
|
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock,
|
|
|
|
&ev) == \-1) {
|
2009-04-24 01:12:53 +00:00
|
|
|
perror("epoll_ctl: conn_sock");
|
2008-11-01 19:30:05 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
2007-04-05 12:36:57 +00:00
|
|
|
} else {
|
2004-11-03 13:51:07 +00:00
|
|
|
do_use_fd(events[n].data.fd);
|
2007-04-05 12:36:57 +00:00
|
|
|
}
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
_syscall.2, capget.2, ioprio_set.2, semop.2, send.2, ctime.3, dysize.3, fenv.3, fmtmsg.3, ftok.3, ftw.3, getaddrinfo.3, getgrent_r.3, gethostbyname.3, getopt.3, getpw.3, getpwent_r.3, getsubopt.3, getutent.3, glob.3, if_nameindex.3, inet.3, lseek64.3, malloc_hook.3, mbrtowc.3, mkstemp.3, mq_receive.3, mq_send.3, posix_spawn.3, putgrent.3, putpwent.3, qsort.3, raise.3, rand.3, rtime.3, setaliasent.3, setbuf.3, shm_open.3, significand.3, sigqueue.3, statvfs.3, strfromd.3, strptime.3, strtol.3, strtoul.3, termios.3, tgamma.3, timeradd.3, tsearch.3, tzset.3, updwtmp.3, usleep.3, wcstok.3, console_codes.4, hd.4, hpsa.4, mem.4, null.4, ram.4, sd.4, ttyS.4, filesystems.5, group.5, passwd.5, shells.5, termcap.5, ttytype.5, tzfile.5, utmp.5, ascii.7, bootparam.7, complex.7, cpuset.7, epoll.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 21:40:17 +00:00
|
|
|
.EE
|
2008-02-28 16:04:59 +00:00
|
|
|
.in
|
environ.7, epoll.7, feature_test_macros.7, futex.7, ip.7, ipv6.7, locale.7, man-pages.7, man.7, math_error.7, netdevice.7, netlink.7, packet.7, raw.7, rtld-audit.7, rtnetlink.7, sock_diag.7, socket.7, tcp.7, udp.7, udplite.7, unix.7, uri.7, vdso.7: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 01:01:48 +00:00
|
|
|
.PP
|
2007-06-14 21:11:22 +00:00
|
|
|
When used as an edge-triggered interface, for performance reasons, it is
|
2008-02-28 16:04:59 +00:00
|
|
|
possible to add the file descriptor inside the
|
|
|
|
.B epoll
|
|
|
|
interface
|
2007-06-14 21:11:22 +00:00
|
|
|
.RB ( EPOLL_CTL_ADD )
|
2007-06-16 05:58:39 +00:00
|
|
|
once by specifying
|
2007-06-14 21:11:22 +00:00
|
|
|
.RB ( EPOLLIN | EPOLLOUT ).
|
2007-04-12 22:42:49 +00:00
|
|
|
This allows you to avoid
|
2004-11-03 13:51:07 +00:00
|
|
|
continuously switching between
|
|
|
|
.B EPOLLIN
|
|
|
|
and
|
|
|
|
.B EPOLLOUT
|
|
|
|
calling
|
|
|
|
.BR epoll_ctl (2)
|
|
|
|
with
|
|
|
|
.BR EPOLL_CTL_MOD .
|
intro.1, time.1, _syscall.2, accept.2, brk.2, capget.2, faccessat.2, futimesat.2, gethostname.2, intro.2, ioprio_set.2, kill.2, madvise.2, mlock.2, mount.2, msgget.2, perf_event_open.2, poll.2, readv.2, sched_rr_get_interval.2, sched_setscheduler.2, select.2, select_tut.2, shmget.2, stat.2, timer_create.2, ustat.2, vfork.2, wait.2, alloca.3, atexit.3, catopen.3, crypt.3, dbopen.3, fenv.3, fopen.3, getaddrinfo_a.3, gethostbyname.3, getutent.3, intro.3, login.3, mallopt.3, queue.3, regex.3, sigpause.3, sigsetops.3, stdio.3, strftime.3, strptime.3, sysconf.3, ttyslot.3, undocumented.3, cciss.4, console_codes.4, hpsa.4, initrd.4, intro.4, rtc.4, st.4, tty_ioctl.4, wavelan.4, acct.5, charmap.5, dir_colors.5, hosts.5, intro.5, termcap.5, utmp.5, intro.6, armscii-8.7, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, ddp.7, epoll.7, glob.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, man-pages.7, man.7, math_error.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, pthreads.7, raw.7, rtnetlink.7, signal.7, socket.7, spufs.7, svipc.7, tcp.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, intro.8: Global fix: use consistent capitalization in .SS headings
Capitalization in .SS sections across pages (and sometimes even
within a single page) is wildly inconsistent. Make it consistent.
Capitalize first word in heading, but otherwise use lower case,
except where English usage (e.g., proper nouns) or programming
language requirements (e.g., identifier names) dictate otherwise.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 14:08:38 +00:00
|
|
|
.SS Questions and answers
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 0. 4
|
2009-01-16 09:23:49 +00:00
|
|
|
What is the key used to distinguish the file descriptors registered in an
|
2018-06-22 10:21:56 +00:00
|
|
|
interest list?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2008-02-28 13:24:52 +00:00
|
|
|
The key is the combination of the file descriptor number and
|
|
|
|
the open file description
|
2008-02-29 16:08:02 +00:00
|
|
|
(also known as an "open file handle",
|
2008-02-28 13:24:52 +00:00
|
|
|
the kernel's internal representation of an open file).
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 1.
|
2009-01-16 09:23:49 +00:00
|
|
|
What happens if you register the same file descriptor on an
|
2008-02-28 16:04:59 +00:00
|
|
|
.B epoll
|
2009-01-16 09:23:49 +00:00
|
|
|
instance twice?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2007-06-22 20:40:07 +00:00
|
|
|
You will probably get
|
|
|
|
.BR EEXIST .
|
2008-02-26 13:29:34 +00:00
|
|
|
However, it is possible to add a duplicate
|
|
|
|
.RB ( dup (2),
|
|
|
|
.BR dup2 (2),
|
|
|
|
.BR fcntl (2)
|
2008-02-28 13:24:52 +00:00
|
|
|
.BR F_DUPFD )
|
2016-01-01 10:45:50 +00:00
|
|
|
file descriptor to the same
|
2008-02-26 13:29:34 +00:00
|
|
|
.B epoll
|
2009-01-16 09:23:49 +00:00
|
|
|
instance.
|
2016-01-01 10:45:50 +00:00
|
|
|
.\" But a file descriptor duplicated by fork(2) can't be added to the
|
2008-02-29 16:08:02 +00:00
|
|
|
.\" set, because the [file *, fd] pair is already in the epoll set.
|
|
|
|
.\" That is a somewhat ugly inconsistency. On the one hand, a child process
|
2008-02-28 13:24:52 +00:00
|
|
|
.\" cannot add the duplicate file descriptor to the epoll set. (In every
|
2016-01-01 10:45:50 +00:00
|
|
|
.\" other case that I can think of, file descriptors duplicated by fork have
|
|
|
|
.\" similar semantics to file descriptors duplicated by dup() and friends.) On
|
2008-02-28 13:24:52 +00:00
|
|
|
.\" the other hand, the very fact that the child has a duplicate of the
|
2016-01-01 10:45:50 +00:00
|
|
|
.\" file descriptor means that even if the parent closes its file descriptor,
|
|
|
|
.\" then epoll_wait() in the parent will continue to receive notifications for
|
|
|
|
.\" that file descriptor because of the duplicated file descriptor in the child.
|
2008-02-28 13:24:52 +00:00
|
|
|
.\"
|
2008-02-29 16:08:02 +00:00
|
|
|
.\" See http://thread.gmane.org/gmane.linux.kernel/596462/
|
|
|
|
.\" "epoll design problems with common fork/exec patterns"
|
2008-03-03 13:24:34 +00:00
|
|
|
.\"
|
2008-02-28 13:24:52 +00:00
|
|
|
.\" mtk, Feb 2008
|
2008-02-26 13:29:34 +00:00
|
|
|
This can be a useful technique for filtering events,
|
|
|
|
if the duplicate file descriptors are registered with different
|
|
|
|
.I events
|
|
|
|
masks.
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 2.
|
2004-11-03 13:51:07 +00:00
|
|
|
Can two
|
|
|
|
.B epoll
|
2009-01-16 09:23:49 +00:00
|
|
|
instances wait for the same file descriptor?
|
2007-04-24 16:44:51 +00:00
|
|
|
If so, are events reported to both
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2007-06-14 21:11:22 +00:00
|
|
|
file descriptors?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2007-06-14 21:11:22 +00:00
|
|
|
Yes, and events would be reported to both.
|
2008-05-21 14:33:28 +00:00
|
|
|
However, careful programming may be needed to do this correctly.
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 3.
|
2004-11-03 13:51:07 +00:00
|
|
|
Is the
|
|
|
|
.B epoll
|
2007-06-14 21:11:22 +00:00
|
|
|
file descriptor itself poll/epoll/selectable?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2004-11-03 13:51:07 +00:00
|
|
|
Yes.
|
2008-02-28 14:25:56 +00:00
|
|
|
If an
|
|
|
|
.B epoll
|
2014-03-26 04:59:48 +00:00
|
|
|
file descriptor has events waiting, then it will
|
2008-02-28 14:25:56 +00:00
|
|
|
indicate as being readable.
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 4.
|
2009-01-16 09:23:49 +00:00
|
|
|
What happens if one attempts to put an
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2009-01-16 09:23:49 +00:00
|
|
|
file descriptor into its own file descriptor set?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2008-02-26 12:34:29 +00:00
|
|
|
The
|
|
|
|
.BR epoll_ctl (2)
|
capget.2, fanotify_init.2, fcntl.2, ioctl_tty.2, madvise.2, mbind.2, prctl.2, sched_setaffinity.2, hash.3, isgreater.3, posix_fallocate.3, sigvec.3, full.4, sd.4, wavelan.4, core.5, host.conf.5, epoll.7, signal.7, unix.7, user_namespaces.7: wfix (will fail --> fail/fails)
Reported-by: Pedro Alves <palves@redhat.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-10-20 10:36:42 +00:00
|
|
|
call fails
|
2008-02-26 12:34:29 +00:00
|
|
|
.RB ( EINVAL ).
|
2007-04-12 22:42:49 +00:00
|
|
|
However, you can add an
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2008-02-28 16:04:59 +00:00
|
|
|
file descriptor inside another
|
|
|
|
.B epoll
|
|
|
|
file descriptor set.
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 5.
|
2008-02-29 16:28:54 +00:00
|
|
|
Can I send an
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
file descriptor over a UNIX domain socket to another process?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2008-02-29 16:28:54 +00:00
|
|
|
Yes, but it does not make sense to do this, since the receiving process
|
2018-06-22 10:21:56 +00:00
|
|
|
would not have copies of the file descriptors in the interest list.
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 6.
|
2007-06-14 21:11:22 +00:00
|
|
|
Will closing a file descriptor cause it to be removed from all
|
2004-11-03 13:51:07 +00:00
|
|
|
.B epoll
|
2018-06-22 10:21:56 +00:00
|
|
|
interest lists?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2008-02-26 12:33:27 +00:00
|
|
|
Yes, but be aware of the following point.
|
|
|
|
A file descriptor is a reference to an open file description (see
|
|
|
|
.BR open (2)).
|
2016-01-01 10:45:50 +00:00
|
|
|
Whenever a file descriptor is duplicated via
|
2008-02-26 12:33:27 +00:00
|
|
|
.BR dup (2),
|
|
|
|
.BR dup2 (2),
|
|
|
|
.BR fcntl (2)
|
|
|
|
.BR F_DUPFD ,
|
|
|
|
or
|
|
|
|
.BR fork (2),
|
|
|
|
a new file descriptor referring to the same open file description is
|
|
|
|
created.
|
|
|
|
An open file description continues to exist until all
|
|
|
|
file descriptors referring to it have been closed.
|
2018-06-22 10:17:42 +00:00
|
|
|
.IP
|
2008-02-29 16:08:02 +00:00
|
|
|
A file descriptor is removed from an
|
2018-06-22 10:17:42 +00:00
|
|
|
interest list only after all the file descriptors referring to the underlying
|
|
|
|
open file description have been closed.
|
2008-02-26 12:33:27 +00:00
|
|
|
This means that even after a file descriptor that is part of an
|
2018-06-22 10:17:42 +00:00
|
|
|
interest list has been closed,
|
2008-02-26 12:33:27 +00:00
|
|
|
events may be reported for that file descriptor if other file
|
|
|
|
descriptors referring to the same underlying file description remain open.
|
2018-06-22 10:17:42 +00:00
|
|
|
To prevent this happening,
|
|
|
|
the file descriptor must be explicitly removed from the interest list (using
|
|
|
|
.BR epoll_ctl (2)
|
|
|
|
.BR EPOLL_CTL_DEL )
|
|
|
|
before it is duplicated.
|
|
|
|
Alternatively,
|
|
|
|
the application must ensure that all file descriptors are closed
|
|
|
|
(which may be difficult if file descriptors were duplicated
|
|
|
|
behind the scenes by library functions that used
|
|
|
|
.BR dup (2)
|
|
|
|
or
|
|
|
|
.BR fork (2)).
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 7.
|
2007-06-14 21:11:22 +00:00
|
|
|
If more than one event occurs between
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_wait (2)
|
|
|
|
calls, are they combined or reported separately?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2004-11-03 13:51:07 +00:00
|
|
|
They will be combined.
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 8.
|
2007-06-21 22:55:04 +00:00
|
|
|
Does an operation on a file descriptor affect the
|
2007-06-14 21:11:22 +00:00
|
|
|
already collected but not yet reported events?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2007-06-14 21:11:22 +00:00
|
|
|
You can do two operations on an existing file descriptor.
|
2007-04-12 22:42:49 +00:00
|
|
|
Remove would be meaningless for
|
|
|
|
this case.
|
close.2, epoll_create.2, epoll_ctl.2, fcntl.2, madvise.2, mmap.2, mremap.2, select_tut.2, setgid.2, setuid.2, syscalls.2, vmsplice.2, dlopen.3, fts.3, getpw.3, stdio.3, fd.4, initrd.4, random.4, sd.4, bootparam.7, capabilities.7, cpuset.7, epoll.7, inotify.7, man.7, socket.7, x25.7: Global fix: s/re-/re/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "re-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 17:45:23 +00:00
|
|
|
Modify will reread available I/O.
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP 9.
|
2007-06-14 21:11:22 +00:00
|
|
|
Do I need to continuously read/write a file descriptor
|
2007-06-22 20:40:07 +00:00
|
|
|
until
|
|
|
|
.B EAGAIN
|
|
|
|
when using the
|
2004-11-03 13:51:07 +00:00
|
|
|
.B EPOLLET
|
2018-06-22 07:27:46 +00:00
|
|
|
flag (edge-triggered behavior)?
|
2018-06-22 07:27:24 +00:00
|
|
|
.IP
|
2007-04-12 22:42:49 +00:00
|
|
|
Receiving an event from
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_wait (2)
|
2008-02-28 13:49:29 +00:00
|
|
|
should suggest to you that such
|
2008-02-28 14:40:15 +00:00
|
|
|
file descriptor is ready for the requested I/O operation.
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
You must consider it ready until the next (nonblocking)
|
2008-02-28 15:54:33 +00:00
|
|
|
read/write yields
|
2007-06-22 20:40:07 +00:00
|
|
|
.BR EAGAIN .
|
2008-02-28 13:49:29 +00:00
|
|
|
When and how you will use the file descriptor is entirely up to you.
|
_syscall.2, capget.2, ioprio_set.2, semop.2, send.2, ctime.3, dysize.3, fenv.3, fmtmsg.3, ftok.3, ftw.3, getaddrinfo.3, getgrent_r.3, gethostbyname.3, getopt.3, getpw.3, getpwent_r.3, getsubopt.3, getutent.3, glob.3, if_nameindex.3, inet.3, lseek64.3, malloc_hook.3, mbrtowc.3, mkstemp.3, mq_receive.3, mq_send.3, posix_spawn.3, putgrent.3, putpwent.3, qsort.3, raise.3, rand.3, rtime.3, setaliasent.3, setbuf.3, shm_open.3, significand.3, sigqueue.3, statvfs.3, strfromd.3, strptime.3, strtol.3, strtoul.3, termios.3, tgamma.3, timeradd.3, tsearch.3, tzset.3, updwtmp.3, usleep.3, wcstok.3, console_codes.4, hd.4, hpsa.4, mem.4, null.4, ram.4, sd.4, ttyS.4, filesystems.5, group.5, passwd.5, shells.5, termcap.5, ttytype.5, tzfile.5, utmp.5, ascii.7, bootparam.7, complex.7, cpuset.7, epoll.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 21:40:17 +00:00
|
|
|
.IP
|
2008-02-28 15:54:33 +00:00
|
|
|
For packet/token-oriented files (e.g., datagram socket,
|
|
|
|
terminal in canonical mode),
|
2008-02-28 16:10:54 +00:00
|
|
|
the only way to detect the end of the read/write I/O space
|
2008-02-28 15:54:33 +00:00
|
|
|
is to continue to read/write until
|
|
|
|
.BR EAGAIN .
|
_syscall.2, capget.2, ioprio_set.2, semop.2, send.2, ctime.3, dysize.3, fenv.3, fmtmsg.3, ftok.3, ftw.3, getaddrinfo.3, getgrent_r.3, gethostbyname.3, getopt.3, getpw.3, getpwent_r.3, getsubopt.3, getutent.3, glob.3, if_nameindex.3, inet.3, lseek64.3, malloc_hook.3, mbrtowc.3, mkstemp.3, mq_receive.3, mq_send.3, posix_spawn.3, putgrent.3, putpwent.3, qsort.3, raise.3, rand.3, rtime.3, setaliasent.3, setbuf.3, shm_open.3, significand.3, sigqueue.3, statvfs.3, strfromd.3, strptime.3, strtol.3, strtoul.3, termios.3, tgamma.3, timeradd.3, tsearch.3, tzset.3, updwtmp.3, usleep.3, wcstok.3, console_codes.4, hd.4, hpsa.4, mem.4, null.4, ram.4, sd.4, ttyS.4, filesystems.5, group.5, passwd.5, shells.5, termcap.5, ttytype.5, tzfile.5, utmp.5, ascii.7, bootparam.7, complex.7, cpuset.7, epoll.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 21:40:17 +00:00
|
|
|
.IP
|
2008-02-28 15:54:33 +00:00
|
|
|
For stream-oriented files (e.g., pipe, FIFO, stream socket), the
|
2008-02-28 13:49:29 +00:00
|
|
|
condition that the read/write I/O space is exhausted can also be detected by
|
|
|
|
checking the amount of data read from / written to the target file
|
|
|
|
descriptor.
|
2007-04-12 22:42:49 +00:00
|
|
|
For example, if you call
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR read (2)
|
2008-02-28 14:40:15 +00:00
|
|
|
by asking to read a certain amount of data and
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR read (2)
|
2008-02-28 13:49:29 +00:00
|
|
|
returns a lower number of bytes, you
|
|
|
|
can be sure of having exhausted the read I/O space for the file
|
|
|
|
descriptor.
|
2008-02-28 14:40:15 +00:00
|
|
|
The same is true when writing using
|
2007-06-14 21:11:22 +00:00
|
|
|
.BR write (2).
|
2008-02-28 15:54:33 +00:00
|
|
|
(Avoid this latter technique if you cannot guarantee that
|
|
|
|
the monitored file descriptor always refers to a stream-oriented file.)
|
intro.1, time.1, _syscall.2, accept.2, brk.2, capget.2, faccessat.2, futimesat.2, gethostname.2, intro.2, ioprio_set.2, kill.2, madvise.2, mlock.2, mount.2, msgget.2, perf_event_open.2, poll.2, readv.2, sched_rr_get_interval.2, sched_setscheduler.2, select.2, select_tut.2, shmget.2, stat.2, timer_create.2, ustat.2, vfork.2, wait.2, alloca.3, atexit.3, catopen.3, crypt.3, dbopen.3, fenv.3, fopen.3, getaddrinfo_a.3, gethostbyname.3, getutent.3, intro.3, login.3, mallopt.3, queue.3, regex.3, sigpause.3, sigsetops.3, stdio.3, strftime.3, strptime.3, sysconf.3, ttyslot.3, undocumented.3, cciss.4, console_codes.4, hpsa.4, initrd.4, intro.4, rtc.4, st.4, tty_ioctl.4, wavelan.4, acct.5, charmap.5, dir_colors.5, hosts.5, intro.5, termcap.5, utmp.5, intro.6, armscii-8.7, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, ddp.7, epoll.7, glob.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, man-pages.7, man.7, math_error.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, pthreads.7, raw.7, rtnetlink.7, signal.7, socket.7, spufs.7, svipc.7, tcp.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, intro.8: Global fix: use consistent capitalization in .SS headings
Capitalization in .SS sections across pages (and sometimes even
within a single page) is wildly inconsistent. Make it consistent.
Capitalize first word in heading, but otherwise use lower case,
except where English usage (e.g., proper nouns) or programming
language requirements (e.g., identifier names) dictate otherwise.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 14:08:38 +00:00
|
|
|
.SS Possible pitfalls and ways to avoid them
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
2007-06-14 21:11:22 +00:00
|
|
|
.B o Starvation (edge-triggered)
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
If there is a large amount of I/O space,
|
|
|
|
it is possible that by trying to drain
|
|
|
|
it the other files will not get processed causing starvation.
|
2007-06-14 21:11:22 +00:00
|
|
|
(This problem is not specific to
|
|
|
|
.BR epoll .)
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
The solution is to maintain a ready list
|
|
|
|
and mark the file descriptor as ready
|
2004-11-03 13:51:07 +00:00
|
|
|
in its associated data structure, thereby allowing the application to
|
|
|
|
remember which files need to be processed but still round robin amongst
|
2007-04-12 22:42:49 +00:00
|
|
|
all the ready files.
|
|
|
|
This also supports ignoring subsequent events you
|
2007-06-14 21:11:22 +00:00
|
|
|
receive for file descriptors that are already ready.
|
2004-11-03 13:51:07 +00:00
|
|
|
.TP
|
2007-04-12 22:42:49 +00:00
|
|
|
.B o If using an event cache...
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-06-14 21:11:22 +00:00
|
|
|
If you use an event cache or store all the file descriptors returned from
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_wait (2),
|
2007-04-12 22:42:49 +00:00
|
|
|
then make sure to provide a way to mark
|
2007-06-14 21:11:22 +00:00
|
|
|
its closure dynamically (i.e., caused by
|
2007-04-12 22:42:49 +00:00
|
|
|
a previous event's processing).
|
|
|
|
Suppose you receive 100 events from
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_wait (2),
|
2007-04-12 22:42:49 +00:00
|
|
|
and in event #47 a condition causes event #13 to be closed.
|
|
|
|
If you remove the structure and
|
2007-05-11 23:29:44 +00:00
|
|
|
.BR close (2)
|
2007-06-14 21:11:22 +00:00
|
|
|
the file descriptor for event #13, then your
|
|
|
|
event cache might still say there are events waiting for that
|
|
|
|
file descriptor causing confusion.
|
2007-04-12 22:42:49 +00:00
|
|
|
.PP
|
2004-11-03 13:51:07 +00:00
|
|
|
One solution for this is to call, during the processing of event 47,
|
|
|
|
.BR epoll_ctl ( EPOLL_CTL_DEL )
|
2007-06-14 21:11:22 +00:00
|
|
|
to delete file descriptor 13 and
|
2007-05-11 23:29:44 +00:00
|
|
|
.BR close (2),
|
2005-10-19 16:30:05 +00:00
|
|
|
then mark its associated
|
2007-04-12 22:42:49 +00:00
|
|
|
data structure as removed and link it to a cleanup list.
|
|
|
|
If you find another
|
2007-06-14 21:11:22 +00:00
|
|
|
event for file descriptor 13 in your batch processing,
|
|
|
|
you will discover the file descriptor had been
|
2004-11-03 13:51:07 +00:00
|
|
|
previously removed and there will be no confusion.
|
2007-05-19 04:30:20 +00:00
|
|
|
.SH VERSIONS
|
2007-11-24 09:51:48 +00:00
|
|
|
The
|
|
|
|
.B epoll
|
|
|
|
API was introduced in Linux kernel 2.5.44.
|
2009-01-16 09:23:49 +00:00
|
|
|
.\" Its interface should be finalized in Linux kernel 2.5.66.
|
2008-11-12 02:22:58 +00:00
|
|
|
Support was added to glibc in version 2.3.2.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH CONFORMING TO
|
2008-02-28 16:04:59 +00:00
|
|
|
The
|
|
|
|
.B epoll
|
|
|
|
API is Linux-specific.
|
2006-06-05 10:59:50 +00:00
|
|
|
Some other systems provide similar
|
2007-06-08 11:56:22 +00:00
|
|
|
mechanisms, for example, FreeBSD has
|
2007-04-12 22:42:49 +00:00
|
|
|
.IR kqueue ,
|
|
|
|
and Solaris has
|
2006-06-05 10:59:50 +00:00
|
|
|
.IR /dev/poll .
|
2016-03-08 18:23:07 +00:00
|
|
|
.SH NOTES
|
|
|
|
The set of file descriptors that is being monitored via
|
|
|
|
an epoll file descriptor can be viewed via the entry for
|
|
|
|
the epoll file descriptor in the process's
|
|
|
|
.IR /proc/[pid]/fdinfo
|
|
|
|
directory.
|
|
|
|
See
|
|
|
|
.BR proc (5)
|
|
|
|
for further details.
|
2017-10-09 09:45:13 +00:00
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.BR kcmp (2)
|
|
|
|
.B KCMP_EPOLL_TFD
|
|
|
|
operation can be used to test whether a file descriptor
|
|
|
|
is present in an epoll instance.
|
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bdflush.2, bind.2, brk.2, cacheflush.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, flock.2, fork.2, fstatat.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpid.2, getpriority.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, getxattr.2, idle.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl.2, ioctl_list.2, ioperm.2, iopl.2, ioprio_set.2, ipc.2, kcmp.2, kill.2, killpg.2, link.2, linkat.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, migrate_pages.2, mincore.2, mkdir.2, mkdirat.2, mknod.2, mknodat.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, mount.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open.2, openat.2, outb.2, pause.2, pciconfig_read.2, perf_event_open.2, perfmonctl.2, personality.2, pipe.2, pivot_root.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readlink.2, readlinkat.2, readv.2, reboot.2, recv.2, remap_file_pages.2, removexattr.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, setup.2, setxattr.2, shmctl.2, shmget.2, shmop.2, shutdown.2, sigaction.2, sigaltstack.2, signal.2, signalfd.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, stat.2, statfs.2, stime.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, sysctl.2, sysfs.2, sysinfo.2, syslog.2, tee.2, time.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, uname.2, unimplemented.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, MB_CUR_MAX.3, MB_LEN_MAX.3, __setfpucw.3, a64l.3, abort.3, abs.3, acos.3, acosh.3, addseverity.3, adjtime.3, aio_cancel.3, aio_error.3, aio_fsync.3, aio_read.3, aio_return.3, aio_suspend.3, aio_write.3, alloca.3, argz_add.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, backtrace.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, btowc.3, btree.3, byteorder.3, bzero.3, cabs.3, cacos.3, cacosh.3, canonicalize_file_name.3, carg.3, casin.3, casinh.3, catan.3, catanh.3, catgets.3, catopen.3, cbrt.3, ccos.3, ccosh.3, ceil.3, cerf.3, cexp.3, cexp2.3, cfree.3, cimag.3, clearenv.3, clock.3, clock_getcpuclockid.3, clog.3, clog10.3, clog2.3, closedir.3, cmsg.3, confstr.3, conj.3, copysign.3, cos.3, cosh.3, cpow.3, cproj.3, creal.3, crypt.3, csin.3, csinh.3, csqrt.3, ctan.3, ctanh.3, ctermid.3, ctime.3, daemon.3, dbopen.3, des_crypt.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dlopen.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, encrypt.3, end.3, endian.3, envz_add.3, erf.3, erfc.3, err.3, errno.3, error.3, ether_aton.3, euidaccess.3, exec.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fclose.3, fcloseall.3, fdim.3, fenv.3, ferror.3, fexecve.3, fflush.3, ffs.3, fgetgrent.3, fgetpwent.3, fgetwc.3, fgetws.3, finite.3, flockfile.3, floor.3, fma.3, fmax.3, fmemopen.3, fmin.3, fmod.3, fmtmsg.3, fnmatch.3, fopen.3, fpathconf.3, fpclassify.3, fpurge.3, fputwc.3, fputws.3, fread.3, frexp.3, fseek.3, fseeko.3, ftime.3, ftok.3, fts.3, ftw.3, futimes.3, fwide.3, gamma.3, gcvt.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getipnodebyname.3, getline.3, getloadavg.3, getlogin.3, getmntent.3, getnameinfo.3, getnetent.3, getnetent_r.3, getopt.3, getpass.3, getprotoent.3, getprotoent_r.3, getpt.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getrpcent_r.3, getrpcport.3, gets.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, getumask.3, getusershell.3, getutent.3, getw.3, getwchar.3, glob.3, grantpt.3, gsignal.3, hash.3, hsearch.3, hypot.3, iconv.3, iconv_close.3, iconv_open.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, isgreater.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, j0.3, key_setsecret.3, ldexp.3, lgamma.3, lio_listio.3, localeconv.3, lockf.3, log.3, log10.3, log1p.3, log2.3, logb.3, login.3, longjmp.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, malloc.3, malloc_hook.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, mempcpy.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mpool.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, nan.3, netlink.3, nextafter.3, nl_langinfo.3, offsetof.3, on_exit.3, opendir.3, openpty.3, perror.3, popen.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, printf.3, profil.3, program_invocation_name.3, psignal.3, pthread_kill_other_threads_np.3, ptsname.3, putenv.3, putgrent.3, putpwent.3, puts.3, putwchar.3, qecvt.3, qsort.3, queue.3, raise.3, rand.3, random.3, random_r.3, rcmd.3, re_comp.3, readdir.3, realpath.3, recno.3, regex.3, remainder.3, remove.3, remquo.3, resolver.3, rewinddir.3, rexec.3, rint.3, round.3, rpc.3, rpmatch.3, rtime.3, rtnetlink.3, scalb.3, scalbln.3, scandir.3, scandirat.3, scanf.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, setlocale.3, setlogmask.3, setnetgrent.3, shm_open.3, siginterrupt.3, signbit.3, significand.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sin.3, sincos.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdarg.3, stdin.3, stdio.3, stdio_ext.3, stpcpy.3, stpncpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfmon.3, strfry.3, strftime.3, string.3, strlen.3, strnlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtod.3, strtoimax.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, termios.3, tgamma.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, towctrans.3, towlower.3, towupper.3, trunc.3, tsearch.3, ttyname.3, ttyslot.3, tzset.3, ualarm.3, ulimit.3, ungetwc.3, unlocked_stdio.3, unlockpt.3, updwtmp.3, usleep.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstoimax.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wordexp.3, wprintf.3, xcrypt.3, xdr.3, y0.3, cciss.4, console.4, console_codes.4, console_ioctl.4, dsp56k.4, fd.4, full.4, hd.4, hpsa.4, initrd.4, intro.4, lp.4, mem.4, mouse.4, null.4, pts.4, ram.4, random.4, rtc.4, sk98lin.4, st.4, tty.4, ttyS.4, tty_ioctl.4, vcs.4, wavelan.4, acct.5, charmap.5, dir_colors.5, filesystems.5, ftpusers.5, group.5, host.conf.5, hosts.5, hosts.equiv.5, intro.5, issue.5, locale.5, motd.5, networks.5, nologin.5, nscd.conf.5, passwd.5, proc.5, protocols.5, resolv.conf.5, rpc.5, securetty.5, services.5, shells.5, termcap.5, ttytype.5, utmp.5, armscii-8.7, arp.7, ascii.7, bootparam.7, capabilities.7, charsets.7, complex.7, cp1251.7, credentials.7, ddp.7, environ.7, epoll.7, fifo.7, futex.7, glob.7, hier.7, icmp.7, inotify.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, locale.7, mailaddr.7, man.7, mq_overview.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, posixoptions.7, pthreads.7, pty.7, raw.7, regex.7, rtld-audit.7, rtnetlink.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, socket.7, standards.7, suffixes.7, svipc.7, tcp.7, termio.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, nscd.8, sync.8, tzselect.8, zdump.8, zic.8: Global fix: remove unneeded double quotes in .SH headings
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 18:01:36 +00:00
|
|
|
.SH SEE ALSO
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_create (2),
|
2008-10-10 14:00:48 +00:00
|
|
|
.BR epoll_create1 (2),
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR epoll_ctl (2),
|
2015-04-16 19:55:35 +00:00
|
|
|
.BR epoll_wait (2),
|
|
|
|
.BR poll (2),
|
|
|
|
.BR select (2)
|