1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 1997 Andries Brouwer (aeb@cwi.nl)
4 .\" and Copyright (C) 2006, Michael Kerrisk <mtk-manpages@gmx.net>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Additions from Richard Gooch <rgooch@atnf.CSIRO.AU> and aeb, 971207
27 .\" 2006-03-13, mtk, Added ppoll() + various other rewordings
28 .\" 2006-07-01, mtk, Added POLLRDHUP + various other wording and
29 .\" formatting changes.
31 .\" FIXME . 2.6.17 has a definition for POLLREMOVE, but this
32 .\" flag is not used in the code. Check later to see if it
33 .\" does get a use. 2.6.21 still shows no use.
35 .TH POLL 2 2006-03-13 "Linux" "Linux Programmer's Manual"
37 poll, ppoll \- wait for some event on a file descriptor
42 .BI "int poll(struct pollfd *" fds ", nfds_t " nfds ", int " timeout );
44 .B #define _GNU_SOURCE
47 .BI "int ppoll(struct pollfd *" fds ", nfds_t " nfds ", "
48 .BI " const struct timespec *" timeout ", const sigset_t *" sigmask );
52 performs a similar task to
54 it waits for one of a set of file descriptors to become ready
57 The set of file descriptors to be monitored is specified in the
59 argument, which is an array of
61 structures of the following form:
65 int fd; /* file descriptor */
66 short events; /* requested events */
67 short revents; /* returned events */
73 contains a file descriptor for an open file.
77 is an input parameter, a bitmask specifying the events the application
82 is an output parameter, filled by the kernel with the events that
86 can include any of those specified in
93 (These three bits are meaningless in the
95 field, and will be set in the
97 field whenever the corresponding condition is true.)
99 If none of the events requested (and no error) has occurred for any
100 of the file descriptors, then
102 blocks until one of the events occurs.
106 argument specifies an upper limit on the time for which
108 will block, in milliseconds.
109 Specifying a negative value in
111 means an infinite timeout.
113 The bits that may be set/returned in
117 are defined in <poll.h>:
121 There is data to read.
124 There is urgent data to read (e.g., out-of-band data on TCP socket;
125 pseudo-terminal master in packet mode has seen state change in slave).
128 Writing now will not block.
130 .BR POLLRDHUP " (since Linux 2.6.17)"
131 Stream socket peer closed connection,
132 or shut down writing half of connection.
135 feature test macro must be defined in order to obtain this definition.
138 Error condition (output only).
141 Hang up (output only).
146 not open (output only).
151 defined, one also has the following,
152 which convey no further information beyond the bits listed above:
160 Priority band data can be read (generally unused on Linux).
161 .\" POLLRDBAND is used in the DECnet protocol.
168 Priority data may be written.
171 Linux also knows about, but does not use
174 The relationship between
178 is analogous to the relationship between
185 allows an application to safely wait until either a file descriptor
186 becomes ready or until a signal is caught.
188 Other than the difference in the
190 argument, the following
195 ready = ppoll(&fds, nfds, timeout, &sigmask);
200 executing the following calls:
205 sigprocmask(SIG_SETMASK, &sigmask, &origmask);
206 ready = poll(&fds, nfds, timeout);
207 sigprocmask(SIG_SETMASK, &origmask, NULL);
210 See the description of
212 for an explanation of why
218 argument specifies an upper limit on the amount of time that
221 This argument is a pointer to a structure of the following form:
226 long tv_sec; /* seconds */
227 long tv_nsec; /* nanoseconds */
234 is specified as NULL, then
236 can block indefinitely.
238 On success, a positive number is returned; this is
239 the number of structures which have non-zero
241 fields (in other words, those descriptors with events or errors reported).
242 A value of 0 indicates that the call timed out and no file
243 descriptors were ready.
244 On error, \-1 is returned, and
246 is set appropriately.
250 An invalid file descriptor was given in one of the sets.
253 The array given as argument was not contained in the calling program's
257 A signal occurred before any requested event.
262 value exceeds the RLIMIT_NOFILE value.
265 There was no space to allocate file descriptor tables.
269 system call was introduced in Linux 2.1.23.
272 library call was introduced in libc 5.4.28
273 (and provides emulation using select(2) if your kernel does not
280 system call was added to Linux in kernel 2.6.16.
283 library call was added in glibc 2.4.
286 conforms to POSIX.1-2001.
289 .\" NetBSD 3.0 has a pollts() which is like Linux ppoll().
291 Some implementations define the non-standard constant
293 with the value \-1 for use as a
295 This constant is not provided in glibc.
299 system call modifies its
302 However, the glibc wrapper function hides this behaviour
303 by using a local variable for the timeout argument that
304 is passed to the system call.
307 function does not modify its
311 See the discussion of spurious readiness notifications under the
317 .BR feature_test_macros (7)