]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Hey Emacs! This file is -*- nroff -*- source. |
2 | .\" | |
3 | .\" Copyright (C) 1997 Andries Brouwer (aeb@cwi.nl) | |
c11b1abf | 4 | .\" and Copyright (C) 2006, Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da MK |
5 | .\" |
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. | |
9 | .\" | |
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. | |
c13182ef | 14 | .\" |
fea681da MK |
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 | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
25 | .\" | |
26 | .\" Additions from Richard Gooch <rgooch@atnf.CSIRO.AU> and aeb, 971207 | |
e755a587 | 27 | .\" 2006-03-13, mtk, Added ppoll() + various other rewordings |
23cb3cb5 MK |
28 | .\" 2006-07-01, mtk, Added POLLRDHUP + various other wording and |
29 | .\" formatting changes. | |
4b9d4c1a | 30 | .\" |
d8dfbff9 | 31 | .TH POLL 2 2009-09-15 "Linux" "Linux Programmer's Manual" |
fea681da | 32 | .SH NAME |
e755a587 | 33 | poll, ppoll \- wait for some event on a file descriptor |
fea681da | 34 | .SH SYNOPSIS |
e755a587 | 35 | .nf |
23cb3cb5 | 36 | .B #include <poll.h> |
fea681da | 37 | .sp |
e755a587 MK |
38 | .BI "int poll(struct pollfd *" fds ", nfds_t " nfds ", int " timeout ); |
39 | .sp | |
22ca838f | 40 | .B #define _GNU_SOURCE |
23cb3cb5 | 41 | .B #include <poll.h> |
22ca838f | 42 | .sp |
e755a587 MK |
43 | .BI "int ppoll(struct pollfd *" fds ", nfds_t " nfds ", " |
44 | .BI " const struct timespec *" timeout ", const sigset_t *" sigmask ); | |
45 | .fi | |
fea681da | 46 | .SH DESCRIPTION |
96296ef0 | 47 | .BR poll () |
e755a587 MK |
48 | performs a similar task to |
49 | .BR select (2): | |
50 | it waits for one of a set of file descriptors to become ready | |
51 | to perform I/O. | |
52 | ||
53 | The set of file descriptors to be monitored is specified in the | |
54 | .I fds | |
d8dfbff9 | 55 | argument, which is an array of structures of the following form: |
088a639b | 56 | .in +4n |
fea681da | 57 | .nf |
96296ef0 | 58 | |
a08ea57c MK |
59 | struct pollfd { |
60 | int fd; /* file descriptor */ | |
61 | short events; /* requested events */ | |
62 | short revents; /* returned events */ | |
63 | }; | |
a08ea57c | 64 | .in |
d8dfbff9 MK |
65 | .fi |
66 | .PP | |
67 | The caller should specify the number of items in the | |
68 | .I fds | |
69 | array in | |
70 | .IR nfds . | |
71 | ||
fea681da MK |
72 | The field |
73 | .I fd | |
74 | contains a file descriptor for an open file. | |
23cb3cb5 | 75 | |
fea681da MK |
76 | The field |
77 | .I events | |
10f5f294 | 78 | is an input parameter, a bit mask specifying the events the application |
fea681da | 79 | is interested in. |
23cb3cb5 | 80 | |
fea681da MK |
81 | The field |
82 | .I revents | |
83 | is an output parameter, filled by the kernel with the events that | |
e755a587 MK |
84 | actually occurred. |
85 | The bits returned in | |
86 | .I revents | |
c13182ef | 87 | can include any of those specified in |
e755a587 MK |
88 | .IR events , |
89 | or one of the values | |
90 | .BR POLLERR , | |
91 | .BR POLLHUP , | |
fea681da MK |
92 | or |
93 | .BR POLLNVAL . | |
94 | (These three bits are meaningless in the | |
95 | .I events | |
96 | field, and will be set in the | |
97 | .I revents | |
98 | field whenever the corresponding condition is true.) | |
23cb3cb5 | 99 | |
fea681da | 100 | If none of the events requested (and no error) has occurred for any |
e755a587 MK |
101 | of the file descriptors, then |
102 | .BR poll () | |
103 | blocks until one of the events occurs. | |
96296ef0 | 104 | |
c13182ef | 105 | The |
e755a587 MK |
106 | .I timeout |
107 | argument specifies an upper limit on the time for which | |
108 | .BR poll () | |
109 | will block, in milliseconds. | |
110 | Specifying a negative value in | |
111 | .I timeout | |
112 | means an infinite timeout. | |
23cb3cb5 MK |
113 | |
114 | The bits that may be set/returned in | |
115 | .I events | |
116 | and | |
117 | .I revents | |
c84371c6 | 118 | are defined in \fI<poll.h>\fP: |
23cb3cb5 MK |
119 | .RS |
120 | .TP | |
121 | .B POLLIN | |
122 | There is data to read. | |
123 | .TP | |
124 | .B POLLPRI | |
c13182ef | 125 | There is urgent data to read (e.g., out-of-band data on TCP socket; |
23cb3cb5 MK |
126 | pseudo-terminal master in packet mode has seen state change in slave). |
127 | .TP | |
128 | .B POLLOUT | |
129 | Writing now will not block. | |
130 | .TP | |
131 | .BR POLLRDHUP " (since Linux 2.6.17)" | |
c13182ef | 132 | Stream socket peer closed connection, |
23cb3cb5 | 133 | or shut down writing half of connection. |
c13182ef | 134 | The |
23cb3cb5 MK |
135 | .B _GNU_SOURCE |
136 | feature test macro must be defined in order to obtain this definition. | |
137 | .TP | |
138 | .B POLLERR | |
139 | Error condition (output only). | |
140 | .TP | |
141 | .B POLLHUP | |
142 | Hang up (output only). | |
143 | .TP | |
144 | .B POLLNVAL | |
c13182ef | 145 | Invalid request: |
23cb3cb5 MK |
146 | .I fd |
147 | not open (output only). | |
148 | .RE | |
149 | .PP | |
c13182ef | 150 | When compiling with |
23cb3cb5 | 151 | .B _XOPEN_SOURCE |
c13182ef | 152 | defined, one also has the following, |
23cb3cb5 MK |
153 | which convey no further information beyond the bits listed above: |
154 | .RS | |
155 | .TP | |
156 | .B POLLRDNORM | |
157 | Equivalent to | |
158 | .BR POLLIN . | |
159 | .TP | |
160 | .B POLLRDBAND | |
161 | Priority band data can be read (generally unused on Linux). | |
162 | .\" POLLRDBAND is used in the DECnet protocol. | |
163 | .TP | |
164 | .B POLLWRNORM | |
165 | Equivalent to | |
166 | .BR POLLOUT . | |
167 | .TP | |
168 | .B POLLWRBAND | |
169 | Priority data may be written. | |
170 | .RE | |
171 | .PP | |
c13182ef | 172 | Linux also knows about, but does not use |
23cb3cb5 | 173 | .BR POLLMSG . |
e755a587 | 174 | .SS ppoll() |
c13182ef | 175 | The relationship between |
e755a587 | 176 | .BR poll () |
c13182ef MK |
177 | and |
178 | .BR ppoll () | |
e755a587 | 179 | is analogous to the relationship between |
0bfa087b | 180 | .BR select (2) |
e755a587 | 181 | and |
0bfa087b | 182 | .BR pselect (2): |
e755a587 | 183 | like |
0bfa087b | 184 | .BR pselect (2), |
e755a587 MK |
185 | .BR ppoll () |
186 | allows an application to safely wait until either a file descriptor | |
187 | becomes ready or until a signal is caught. | |
188 | .PP | |
c13182ef | 189 | Other than the difference in the |
e755a587 | 190 | .I timeout |
c13182ef | 191 | argument, the following |
e755a587 MK |
192 | .BR ppoll () |
193 | call: | |
194 | .nf | |
195 | ||
196 | ready = ppoll(&fds, nfds, timeout, &sigmask); | |
197 | ||
198 | .fi | |
199 | is equivalent to | |
200 | .I atomically | |
201 | executing the following calls: | |
202 | .nf | |
203 | ||
204 | sigset_t origmask; | |
205 | ||
206 | sigprocmask(SIG_SETMASK, &sigmask, &origmask); | |
00877d8f | 207 | ready = poll(&fds, nfds, timeout); |
e755a587 MK |
208 | sigprocmask(SIG_SETMASK, &origmask, NULL); |
209 | .fi | |
210 | .PP | |
211 | See the description of | |
212 | .BR pselect (2) | |
213 | for an explanation of why | |
214 | .BR ppoll () | |
215 | is necessary. | |
216 | ||
3ee89512 MK |
217 | If the |
218 | .I sigmask | |
219 | argument is specified as NULL, then | |
220 | no signal mask manipulation is performed | |
221 | (and thus | |
222 | .BR ppoll () | |
223 | differs from | |
224 | .BR poll () | |
225 | only in the precision of the | |
226 | .I timeout | |
227 | argument). | |
228 | ||
e755a587 MK |
229 | The |
230 | .I timeout | |
c13182ef | 231 | argument specifies an upper limit on the amount of time that |
e755a587 MK |
232 | .BR ppoll () |
233 | will block. | |
234 | This argument is a pointer to a structure of the following form: | |
088a639b | 235 | .in +4n |
e755a587 MK |
236 | .nf |
237 | ||
238 | struct timespec { | |
239 | long tv_sec; /* seconds */ | |
240 | long tv_nsec; /* nanoseconds */ | |
241 | }; | |
242 | .fi | |
a08ea57c | 243 | .in |
e755a587 MK |
244 | |
245 | If | |
246 | .I timeout | |
c13182ef | 247 | is specified as NULL, then |
e755a587 MK |
248 | .BR ppoll () |
249 | can block indefinitely. | |
fea681da | 250 | .SH "RETURN VALUE" |
96296ef0 | 251 | On success, a positive number is returned; this is |
c7094399 | 252 | the number of structures which have nonzero |
fea681da MK |
253 | .I revents |
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 | |
c13182ef MK |
256 | descriptors were ready. |
257 | On error, \-1 is returned, and | |
fea681da MK |
258 | .I errno |
259 | is set appropriately. | |
260 | .SH ERRORS | |
261 | .TP | |
fea681da MK |
262 | .B EFAULT |
263 | The array given as argument was not contained in the calling program's | |
264 | address space. | |
265 | .TP | |
266 | .B EINTR | |
01538d0d MK |
267 | A signal occurred before any requested event; see |
268 | .BR signal (7). | |
fea681da MK |
269 | .TP |
270 | .B EINVAL | |
271 | The | |
272 | .I nfds | |
682edefb MK |
273 | value exceeds the |
274 | .B RLIMIT_NOFILE | |
275 | value. | |
fea681da MK |
276 | .TP |
277 | .B ENOMEM | |
278 | There was no space to allocate file descriptor tables. | |
e755a587 | 279 | .SH VERSIONS |
b5cc2ffb | 280 | The |
c13182ef | 281 | .BR poll () |
b5cc2ffb | 282 | system call was introduced in Linux 2.1.23. |
c13182ef | 283 | The |
4d52e8f8 | 284 | .BR poll () |
b5cc2ffb | 285 | library call was introduced in libc 5.4.28 |
0bfa087b | 286 | (and provides emulation using select(2) if your kernel does not |
c13182ef | 287 | have a |
1e321034 MK |
288 | .BR poll () |
289 | system call). | |
e755a587 MK |
290 | |
291 | The | |
292 | .BR ppoll () | |
293 | system call was added to Linux in kernel 2.6.16. | |
294 | The | |
295 | .BR ppoll () | |
296 | library call was added in glibc 2.4. | |
a1d5f77c MK |
297 | .SH "CONFORMING TO" |
298 | .BR poll () | |
299 | conforms to POSIX.1-2001. | |
300 | .BR ppoll () | |
8382f16d | 301 | is Linux-specific. |
a1d5f77c | 302 | .\" NetBSD 3.0 has a pollts() which is like Linux ppoll(). |
e755a587 | 303 | .SH NOTES |
c8f2dd47 | 304 | Some implementations define the nonstandard constant |
c1164764 MK |
305 | .B INFTIM |
306 | with the value \-1 for use as a | |
307 | .IR timeout . | |
308 | This constant is not provided in glibc. | |
4fb31341 MK |
309 | .SS "Linux Notes" |
310 | The Linux | |
311 | .BR ppoll () | |
312 | system call modifies its | |
313 | .I timeout | |
314 | argument. | |
d9bfdb9c | 315 | However, the glibc wrapper function hides this behavior |
4fb31341 MK |
316 | by using a local variable for the timeout argument that |
317 | is passed to the system call. | |
318 | Thus, the glibc | |
319 | .BR ppoll () | |
320 | function does not modify its | |
321 | .I timeout | |
322 | argument. | |
a1d5f77c MK |
323 | .SH BUGS |
324 | See the discussion of spurious readiness notifications under the | |
325 | BUGS section of | |
326 | .BR select (2). | |
fea681da MK |
327 | .SH "SEE ALSO" |
328 | .BR select (2), | |
50e5322c | 329 | .BR select_tut (2), |
1d7c4d16 MK |
330 | .BR feature_test_macros (7), |
331 | .BR time (7) |