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@gmail.com>
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 .TH POLL 2 2009-09-15 "Linux" "Linux Programmer's Manual"
33 poll, ppoll \- wait for some event on a file descriptor
38 .BI "int poll(struct pollfd *" fds ", nfds_t " nfds ", int " timeout );
40 .B #define _GNU_SOURCE
43 .BI "int ppoll(struct pollfd *" fds ", nfds_t " nfds ", "
44 .BI " const struct timespec *" timeout ", const sigset_t *" sigmask );
48 performs a similar task to
50 it waits for one of a set of file descriptors to become ready
53 The set of file descriptors to be monitored is specified in the
55 argument, which is an array of structures of the following form:
60 int fd; /* file descriptor */
61 short events; /* requested events */
62 short revents; /* returned events */
67 The caller should specify the number of items in the
74 contains a file descriptor for an open file.
78 is an input parameter, a bit mask specifying the events the application
83 is an output parameter, filled by the kernel with the events that
87 can include any of those specified in
94 (These three bits are meaningless in the
96 field, and will be set in the
98 field whenever the corresponding condition is true.)
100 If none of the events requested (and no error) has occurred for any
101 of the file descriptors, then
103 blocks until one of the events occurs.
107 argument specifies an upper limit on the time for which
109 will block, in milliseconds.
110 Specifying a negative value in
112 means an infinite timeout.
114 The bits that may be set/returned in
118 are defined in \fI<poll.h>\fP:
122 There is data to read.
125 There is urgent data to read (e.g., out-of-band data on TCP socket;
126 pseudo-terminal master in packet mode has seen state change in slave).
129 Writing now will not block.
131 .BR POLLRDHUP " (since Linux 2.6.17)"
132 Stream socket peer closed connection,
133 or shut down writing half of connection.
136 feature test macro must be defined in order to obtain this definition.
139 Error condition (output only).
142 Hang up (output only).
147 not open (output only).
152 defined, one also has the following,
153 which convey no further information beyond the bits listed above:
161 Priority band data can be read (generally unused on Linux).
162 .\" POLLRDBAND is used in the DECnet protocol.
169 Priority data may be written.
172 Linux also knows about, but does not use
175 The relationship between
179 is analogous to the relationship between
186 allows an application to safely wait until either a file descriptor
187 becomes ready or until a signal is caught.
189 Other than the difference in the
191 argument, the following
196 ready = ppoll(&fds, nfds, timeout, &sigmask);
201 executing the following calls:
206 sigprocmask(SIG_SETMASK, &sigmask, &origmask);
207 ready = poll(&fds, nfds, timeout);
208 sigprocmask(SIG_SETMASK, &origmask, NULL);
211 See the description of
213 for an explanation of why
219 argument is specified as NULL, then
220 no signal mask manipulation is performed
225 only in the precision of the
231 argument specifies an upper limit on the amount of time that
234 This argument is a pointer to a structure of the following form:
239 long tv_sec; /* seconds */
240 long tv_nsec; /* nanoseconds */
247 is specified as NULL, then
249 can block indefinitely.
251 On success, a positive number is returned; this is
252 the number of structures which have nonzero
254 fields (in other words, those descriptors with events or errors reported).
255 A value of 0 indicates that the call timed out and no file
256 descriptors were ready.
257 On error, \-1 is returned, and
259 is set appropriately.
263 The array given as argument was not contained in the calling program's
267 A signal occurred before any requested event; see
278 There was no space to allocate file descriptor tables.
282 system call was introduced in Linux 2.1.23.
285 library call was introduced in libc 5.4.28
286 (and provides emulation using select(2) if your kernel does not
293 system call was added to Linux in kernel 2.6.16.
296 library call was added in glibc 2.4.
299 conforms to POSIX.1-2001.
302 .\" NetBSD 3.0 has a pollts() which is like Linux ppoll().
304 Some implementations define the nonstandard constant
306 with the value \-1 for use as a
308 This constant is not provided in glibc.
312 system call modifies its
315 However, the glibc wrapper function hides this behavior
316 by using a local variable for the timeout argument that
317 is passed to the system call.
320 function does not modify its
324 See the discussion of spurious readiness notifications under the
330 .BR feature_test_macros (7),