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 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
32 .\" all rights reserved.
33 .\" Translated 1997-12-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
34 .\" Updated & Modified 2004-05-22, Yuichi SATO <ysato444@yahoo.co.jp>
35 .\" Updated & Modified 2005-01-03, Yuichi SATO
36 .\" Updated & Modified 2005-10-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
37 .\" Updated 2005-12-05, Akihiro MOTOKI, Catch up to LDP man-pages 2.16
38 .\" Updated 2006-04-16, Akihiro MOTOKI, Catch up to LDP man-pages 2.28
39 .\" Updated 2006-07-23, Akihiro MOTOKI, Catch up to LDP man-pages 2.36
41 .\"WORD: descriptor ¥Ç¥£¥¹¥¯¥ê¥×¥¿
43 .TH POLL 2 2009-09-15 "Linux" "Linux Programmer's Manual"
46 .\"O poll, ppoll \- wait for some event on a file descriptor
47 poll, ppoll \- ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë¤ª¤±¤ë¥¤¥Ù¥ó¥È¤òÂÔ¤Ä
53 .BI "int poll(struct pollfd *" fds ", nfds_t " nfds ", int " timeout );
55 .B #define _GNU_SOURCE
58 .BI "int ppoll(struct pollfd *" fds ", nfds_t " nfds ", "
59 .BI " const struct timespec *" timeout ", const sigset_t *" sigmask );
64 .\"O performs a similar task to
66 .\"O it waits for one of a set of file descriptors to become ready
71 ¤ÈƱÍͤλŻö¤ò¹Ô¤¦¡¢¤Ä¤Þ¤ê¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿½¸¹ç¤Î¤¤¤º¤ì¤«°ì¤Ä¤¬
72 I/O ¤ò¼Â¹Ô²Äǽ¤Ê¾õÂ֤ˤʤë¤Î¤òÂԤġ£
74 .\"O The set of file descriptors to be monitored is specified in the
76 .\"O argument, which is an array of structures of the following form:
77 ´Æ»ë¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿½¸¹ç¤Ï¡¢
81 ¤Ï¡¢°Ê²¼¤Î·¿¤Î¹½Â¤ÂΤÎÇÛÎó¤Ç¤¢¤ë¡£
86 int fd; /* file descriptor */
87 short events; /* requested events */
88 short revents; /* returned events */
93 .\"O The caller should specify the number of items in the
100 ÇÛÎó¤ÎÍ×ÁÇ¿ô¤ò»ØÄꤹ¤ë¡£
104 .\"O contains a file descriptor for an open file.
107 ¤Ë¤Ï¥ª¡¼¥×¥ó¤·¤¿¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÆþ¤ì¤ë¡£
111 .\"O is an input parameter, a bit mask specifying the events the application
112 .\"O is interested in.
115 Í×ÁǤÏÆþÎϥѥé¥á¡¼¥¿¤Ç¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¶½Ì£¤ò»ý¤Ã¤Æ¤¤¤ë¥¤¥Ù¥ó¥È¤Î
116 ¥Ó¥Ã¥È¥Þ¥¹¥¯¤ò»ØÄꤹ¤ë¡£
120 .\"O is an output parameter, filled by the kernel with the events that
121 .\"O actually occurred.
122 .\"O The bits returned in
124 .\"O can include any of those specified in
126 .\"O or one of the values
131 .\"O (These three bits are meaningless in the
133 .\"O field, and will be set in the
135 .\"O field whenever the corresponding condition is true.)
137 Í×ÁǤϽÐÎϥѥé¥á¡¼¥¿¤Ç¡¢¼ÂºÝ¤Ëµ¯¤³¤Ã¤¿¥¤¥Ù¥ó¥È¤¬¥«¡¼¥Í¥ë¤Ë¤è¤êÀßÄꤵ¤ì¤ë¡£
139 ¤ÇÊÖ¤µ¤ì¤ë¥Ó¥Ã¥ÈÎó¤Ë¤Ï¡¢
141 ¤Ç»ØÄꤷ¤¿¤â¤Î¤Î¤É¤ì¤«¡¢¤â¤·¤¯¤Ï
145 ¤Î¤¦¤Á¤Î°ì¤Ä¤¬´Þ¤Þ¤ì¤ë
151 ¤Ë»ØÄꤷ¤Æ¤â°ÕÌ£¤¬¤Ê¤¯¡¢Âбþ¤·¤¿¾õÂÖ¤¬¿¿¤Î¾ì¹ç¤Ë
155 .\"O If none of the events requested (and no error) has occurred for any
156 .\"O of the file descriptors, then
158 .\"O blocks until one of the events occurs.
159 ¤É¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ë¤âÍ׵ᤷ¤¿¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤Æ¤ª¤é¤º¡¢
160 ¥¨¥é¡¼¤âµ¯¤³¤é¤Ê¤¤¾ì¹ç¡¢
162 ¤Ï¥¤¥Ù¥ó¥È¤Î¤¦¤Á¤¤¤º¤ì¤«°ì¤Ä¤¬È¯À¸¤¹¤ë¤Þ¤ÇÄä»ß (block) ¤¹¤ë¡£
166 .\"O argument specifies an upper limit on the time for which
168 .\"O will block, in milliseconds.
169 .\"O Specifying a negative value in
171 .\"O means an infinite timeout.
175 ¤¬Ää»ß¤¹¤ë»þ´Ö¤Î¾å¸Â¤òÀßÄꤹ¤ë¤â¤Î¤Ç¡¢¥ß¥êÉÃñ°Ì¤Ç»ØÄꤹ¤ë¡£
177 ¤ËÉé¤ÎÃͤò»ØÄꤹ¤ë¤È¡¢¥¿¥¤¥à¥¢¥¦¥È»þ´Ö¤¬Ìµ¸Â¤È¤Ê¤ë¡£
179 .\"O The bits that may be set/returned in
183 .\"O are defined in \fI<poll.h>\fP:
187 ¤ÇÊÖ¤µ¤ì¤ë¥Ó¥Ã¥È¤Ï \fI<poll.h>\fP ¤ÇÄêµÁ¤µ¤ì¤Æ¤¤¤ë:
191 .\"O There is data to read.
192 Æɤ߽Ф·²Äǽ¤Ê¥Ç¡¼¥¿¤¬¤¢¤ë¡£
195 .\"O There is urgent data to read (e.g., out-of-band data on TCP socket;
196 .\"O pseudo-terminal master in packet mode has seen state change in slave).
197 Æɤ߽Ф·²Äǽ¤Ê¶ÛµÞ¥Ç¡¼¥¿ (urgent data) ¤¬¤¢¤ë
198 (Î㤨¤Ð¡¢TCP ¥½¥±¥Ã¥È¤ÎÂÓ°è³° (out-of-band data) ¥Ç¡¼¥¿¤ò¼õ¿®¤·¤¿¾ì¹ç¤ä¡¢
199 ¥Ñ¥±¥Ã¥È¥â¡¼¥É¤Îµ¼»÷üËö¤Î¥Þ¥¹¥¿¤¬¥¹¥ì¡¼¥Ö¦¤ÎÊѲ½¤ò¸«¤Ä¤±¤¿¤È¤)¡£
202 .\"O Writing now will not block.
203 ½ñ¤¹þ¤ß¤¬Ää»ß (block) ¤·¤Ê¤¤¾õÂ֤Ǥ¢¤ë¡£
205 .\"O .BR POLLRDHUP " (since Linux 2.6.17)"
206 .BR POLLRDHUP " (Linux 2.6.17 °Ê¹ß)"
207 .\"O Stream socket peer closed connection,
208 .\"O or shut down writing half of connection.
211 .\"O feature test macro must be defined in order to obtain this definition.
212 ¥¹¥È¥ê¡¼¥à¥½¥±¥Ã¥È¤Î¾ü¤¬¡¢¥³¥Í¥¯¥·¥ç¥ó¤ò close ¤·¤¿¤«¡¢
213 ¥³¥Í¥¯¥·¥ç¥ó¤Î½ñ¤¹þ¤ß¦¤ò shutdown ¤·¤¿¡£
214 ¤³¤ÎÄêµÁ¤ò͸ú¤Ë¤¹¤ë¤Ë¤Ï¡¢
216 µ¡Ç½¸¡ºº¥Þ¥¯¥í¤òÄêµÁ¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
219 .\"O Error condition (output only).
220 ¥¨¥é¡¼¾õÂÖ (½ÐÎϤξì¹ç¤Î¤ß)¡£
223 .\"O Hang up (output only).
224 ¥Ï¥ó¥°¥¢¥Ã¥×¤·¤¿ (½ÐÎϤξì¹ç¤Î¤ß)¡£
227 .\"O Invalid request:
229 .\"O not open (output only).
232 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤Ê¤¤ (½ÐÎϤξì¹ç¤Î¤ß)¡£
235 .\"O When compiling with
236 .\"O .B _XOPEN_SOURCE
237 .\"O defined, one also has the following,
238 .\"O which convey no further information beyond the bits listed above:
240 ¤òÄêµÁ¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¤·¤¿¾ì¹ç¤Ë¤Ï¡¢°Ê²¼¤ÎÄêµÁ¤â¹Ô¤ï¤ì¤ë¡£
241 ¤¿¤À¤·¡¢¾åµ¤Î¥ê¥¹¥È¤Ë¤¢¤ë¥Ó¥Ã¥È°Ê¾å¤Î¾ðÊó¤¬ÆÀ¤é¤ì¤ëÌõ¤Ç¤Ï¤Ê¤¤¡£
251 .\"O Priority band data can be read (generally unused on Linux).
252 Í¥ÀèÂÓ°è¥Ç¡¼¥¿ (priority band data) ¤¬Æɤ߽Ф·²Äǽ¤Ç¤¢¤ë
253 (ÉáÄÌ¤Ï Linux ¤Ç¤Ï»ÈÍѤµ¤ì¤Ê¤¤)¡£
254 .\" POLLRDBAND is used in the DECnet protocol.
263 .\"O Priority data may be written.
264 Í¥ÀèÂÓ°è¥Ç¡¼¥¿ (priority data) ¤¬½ñ¤¹þ¤ß²Äǽ¤Ç¤¢¤ë¡£
267 .\"O Linux also knows about, but does not use
271 ¤âÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤¬¡¢»ÈÍѤµ¤ì¤Æ¤¤¤Ê¤¤¡£
273 .\"O The relationship between
277 .\"O is analogous to the relationship between
280 .\"O .BR pselect (2):
282 .\"O .BR pselect (2),
284 .\"O allows an application to safely wait until either a file descriptor
285 .\"O becomes ready or until a signal is caught.
293 ¤Î´Ø·¸¤ÈƱ¤¸¤è¤¦¤Ê¤â¤Î¤Ç¤¢¤ë:
297 ¤ò»È¤¦¤È¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¾õÂÖÊѲ½
298 ¤â¤·¤¯¤Ï¥·¥°¥Ê¥ë¤ÎÊ᪤ò°ÂÁ´¤ËÂԤĤ³¤È¤¬¤Ç¤¤ë¡£
300 .\"O Other than the difference in the
302 .\"O argument, the following
306 °ú¤¿ô¤Î°ã¤¤¤ò½ü¤¯¤È¡¢°Ê²¼¤Î
311 ready = ppoll(&fds, nfds, timeout, &sigmask);
314 .\"O is equivalent to
316 .\"O executing the following calls:
319 ¤Ë¼Â¹Ô¤¹¤ë¤Î¤ÈÅù²Á¤Ç¤¢¤ë¡£
324 sigprocmask(SIG_SETMASK, &sigmask, &origmask);
325 ready = poll(&fds, nfds, timeout);
326 sigprocmask(SIG_SETMASK, &origmask, NULL);
329 .\"O See the description of
331 .\"O for an explanation of why
336 ¤¬É¬ÍפʤΤ«¤Ë¤Ä¤¤¤Æ¤ÎÀâÌÀ¤Ï
342 .\"O argument is specified as NULL, then
343 .\"O no signal mask manipulation is performed
348 .\"O only in the precision of the
352 °ú¤¿ô¤Ë NULL ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢¥·¥°¥Ê¥ë¥Þ¥¹¥¯¤ÎÁàºî¤Ï¹Ô¤ï¤ì¤Ê¤¤
359 °ú¤¿ô¤ÎÀºÅÙ¤À¤±¤È¤Ê¤ë)¡£
363 .\"O argument specifies an upper limit on the amount of time that
366 .\"O This argument is a pointer to a structure of the following form:
370 ¤¬Ää»ß¤¹¤ë»þ´Ö¤Î¾å¸Â¤ò»ØÄꤹ¤ë¤â¤Î¤Ç¤¢¤ë¡£
371 ¤³¤Î°ú¤¿ô¤Ë¤Ï°Ê²¼¤Î·¿¤Î¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤ò»ØÄꤹ¤ë¡£
376 long tv_sec; /* seconds */
377 long tv_nsec; /* nanoseconds */
384 .\"O is specified as NULL, then
386 .\"O can block indefinitely.
388 ¤Ë NULL ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢
390 ¤Ï̵¸Â¤ËÄä»ß¤¹¤ë¤³¤È¤¬¤¢¤êÆÀ¤ë¡£
391 .\"O .SH "RETURN VALUE"
393 .\"O On success, a positive number is returned; this is
394 .\"O the number of structures which have nonzero
396 .\"O fields (in other words, those descriptors with events or errors reported).
397 .\"O A value of 0 indicates that the call timed out and no file
398 .\"O descriptors were ready.
399 .\"O On error, \-1 is returned, and
401 .\"O is set appropriately.
402 À®¸ù¤·¤¿¾ì¹ç¤ÏÀµ¤Î¿ô¤òÊÖ¤¹¡£¤³¤Î¿ô¤Ï 0 °Ê³°¤Î
404 Í×ÁǤò»ý¤Ä¹½Â¤ÂΤοô¤Ç¤¢¤ë (Ê̤θÀ¤¤Êý¤ò¤¹¤ë¤È¡¢¤³¤ì¤é¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿
405 ¤Ë¤Ï¥¤¥Ù¥ó¥È¤«¥¨¥é¡¼Êó¹ð¤¬¤¢¤ë)¡£
406 ÃÍ 0 ¤Ï¡¢¥¿¥¤¥à¥¢¥¦¥È¤È¤Ê¤ê¡¢¤É¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤â¥¤¥Ù¥ó¥È¤¬
407 ȯÀ¸¤·¤Ê¤«¤Ã¤¿¤³¤È¤ò¼¨¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï \-1 ¤¬ÊÖ¤µ¤ì¡¢
414 .\"O The array given as argument was not contained in the calling program's
416 °ú¤¿ô¤È¤·¤Æ»ØÄꤷ¤¿ÇÛÎ󤬡¢¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥¢¥É¥ì¥¹¶õ´Ö¤Ë
420 .\"O A signal occurred before any requested event; see
422 Í׵ᤵ¤ì¤¿¥¤¥Ù¥ó¥È¤Î¤É¤ì¤«¤¬µ¯¤³¤ëÁ°¤Ë¥·¥°¥Ê¥ë¤¬È¯À¸¤·¤¿¡£
429 .\"O value exceeds the
430 .\"O .B RLIMIT_NOFILE
438 .\"O There was no space to allocate file descriptor tables.
439 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¦¥Æ¡¼¥Ö¥ë¤ò³ÎÊݤ¹¤ë¤¿¤á¤Î¥á¥â¥ê¤¬¤Ê¤¤¡£
444 .\"O system call was introduced in Linux 2.1.23.
447 .\"O library call was introduced in libc 5.4.28
448 .\"O (and provides emulation using select(2) if your kernel does not
453 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 2.1.23 ¤ÇƳÆþ¤µ¤ì¤¿¡£
455 ¥é¥¤¥Ö¥é¥ê¡¦¥³¡¼¥ë¤Ï libc 5.4.28 ¤«¤éƳÆþ¤µ¤ì¤¿
458 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë
460 ¤ò»ÈÍѤ·¤Æ¥¨¥ß¥å¥ì¡¼¥È¤ò¹Ô¤¦)¡£
464 .\"O system call was added to Linux in kernel 2.6.16.
467 .\"O library call was added in glibc 2.4.
469 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï ¥«¡¼¥Í¥ë 2.6.16 ¤Ç Linux ¤ËÄɲ䵤줿¡£
471 ¥é¥¤¥Ö¥é¥ê¥³¡¼¥ë¤Ï glibc 2.4 ¤ËÄɲ䵤줿¡£
472 .\"O .SH "CONFORMING TO"
475 .\"O conforms to POSIX.1-2001.
477 .\"O is Linux-specific.
478 .\"O .\" NetBSD 3.0 has a pollts() which is like Linux ppoll().
480 ¤Ï POSIX.1-2001 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
482 ¤Ï Linux ¸ÇͤǤ¢¤ë¡£
483 .\" NetBSD 3.0 ¤Ë¤Ï pollts() ¤¬¤¢¤ë¡£
484 .\" pollts() ¤Ï Linux ppoll () ¤ÈƱ¤¸¤è¤¦¤Ê¤â¤Î¤Ç¤¢¤ë¡£
487 .\"O Some implementations define the nonstandard constant
489 .\"O with the value \-1 for use as a
491 .\"O This constant is not provided in glibc.
492 ¤¤¤¯¤Ä¤«¤Î¼ÂÁõ¤Ç¤Ï¡¢ÃÍ \-1 ¤ò»ý¤Ã¤¿Èóɸ½à¤ÎÄê¿ô
497 ¤³¤ÎÄê¿ô¤Ï glibc ¤Ç¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
498 .\"O .SS "LINUX NOTES"
502 .\"O system call modifies its
505 .\"O However, the glibc wrapper function hides this behavior
506 .\"O by using a local variable for the timeout argument that
507 .\"O is passed to the system call.
510 .\"O function does not modify its
518 ¤·¤«¤·¡¢glibc ¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ï¡¢¥·¥¹¥Æ¥à¥³¡¼¥ë¤ËÅϤ¹ timeout °ú¤¿ô
519 ¤È¤·¤Æ¥í¡¼¥«¥ëÊÑ¿ô¤ò»È¤¦¤³¤È¤Ç¤³¤ÎÆ°ºî¤ò±£Ê䷤Ƥ¤¤ë¡£
527 .\"O See the discussion of spurious readiness notifications under the
531 ¤Î¡Ö¥Ð¥°¡×¤ÎÀá¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¡¢¸í¤Ã¤¿½àÈ÷´°Î»ÄÌÃÎ (spurious readiness
532 notifications) ¤Ë¤Ä¤¤¤Æ¤ÎµÄÏÀ¤ò»²¾È¤Î¤³¤È¡£
537 .BR feature_test_macros (7),