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 2010-09-20 "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 .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
56 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */"
59 .BI "int ppoll(struct pollfd *" fds ", nfds_t " nfds ", "
60 .BI " const struct timespec *" timeout_ts ", const sigset_t *" sigmask );
65 .\"O performs a similar task to
67 .\"O it waits for one of a set of file descriptors to become ready
72 と同様の仕事を行う、つまり、ファイルディスクリプタ集合のいずれか一つが
75 .\"O The set of file descriptors to be monitored is specified in the
77 .\"O argument, which is an array of structures of the following form:
87 int fd; /* file descriptor */
88 short events; /* requested events */
89 short revents; /* returned events */
94 .\"O The caller should specify the number of items in the
105 .\"O contains a file descriptor for an open file.
108 にはオープンしたファイルのファイルディスクリプタを入れる。
112 .\"O is an input parameter, a bit mask specifying the events the application
113 .\"O is interested in.
116 要素は入力パラメータで、アプリケーションが興味を持っているイベントの
121 .\"O is an output parameter, filled by the kernel with the events that
122 .\"O actually occurred.
123 .\"O The bits returned in
125 .\"O can include any of those specified in
127 .\"O or one of the values
132 .\"O (These three bits are meaningless in the
134 .\"O field, and will be set in the
136 .\"O field whenever the corresponding condition is true.)
138 要素は出力パラメータで、実際に起こったイベントがカーネルにより設定される。
152 に指定しても意味がなく、対応した状態が真の場合に
156 .\"O If none of the events requested (and no error) has occurred for any
157 .\"O of the file descriptors, then
159 .\"O blocks until one of the events occurs.
160 どのファイルディスクリプタにも要求したイベントが発生しておらず、
163 はイベントのうちいずれか一つが発生するまで停止 (block) する。
167 .\"O argument specifies an upper limit on the time for which
169 .\"O will block, in milliseconds.
170 .\"O Specifying a negative value in
172 .\"O means an infinite timeout.
176 が停止する時間の上限を設定するもので、ミリ秒単位で指定する。
178 に負の値を指定すると、タイムアウト時間が無限となる。
180 .\"O The bits that may be set/returned in
184 .\"O are defined in \fI<poll.h>\fP:
188 で返されるビットは \fI<poll.h>\fP で定義されている:
192 .\"O There is data to read.
196 .\"O There is urgent data to read (e.g., out-of-band data on TCP socket;
197 .\"O pseudoterminal master in packet mode has seen state change in slave).
198 読み出し可能な緊急データ (urgent data) がある
199 (例えば、TCP ソケットの帯域外 (out-of-band data) データを受信した場合や、
200 パケットモードの擬似端末のマスタがスレーブ側の変化を見つけたとき)。
203 .\"O Writing now will not block.
204 書き込みが停止 (block) しない状態である。
206 .\"O .BR POLLRDHUP " (since Linux 2.6.17)"
207 .BR POLLRDHUP " (Linux 2.6.17 以降)"
208 .\"O Stream socket peer closed connection,
209 .\"O or shut down writing half of connection.
212 .\"O feature test macro must be defined
213 .\"O (before including
216 .\"O in order to obtain this definition.
217 ストリームソケットの他端が、コネクションを close したか、
218 コネクションの書き込み側を shutdown した。
220 (「どの」ヘッダファイルをインクルードするよりも前に)
225 .\"O Error condition (output only).
229 .\"O Hang up (output only).
233 .\"O Invalid request:
235 .\"O not open (output only).
238 がオープンされていない (出力の場合のみ)。
241 .\"O When compiling with
242 .\"O .B _XOPEN_SOURCE
243 .\"O defined, one also has the following,
244 .\"O which convey no further information beyond the bits listed above:
246 を定義してコンパイルした場合には、以下の定義も行われる。
247 ただし、上記のリストにあるビット以上の情報が得られる訳ではない。
257 .\"O Priority band data can be read (generally unused on Linux).
258 優先帯域データ (priority band data) が読み出し可能である
259 (普通は Linux では使用されない)。
260 .\" POLLRDBAND is used in the DECnet protocol.
269 .\"O Priority data may be written.
270 優先帯域データ (priority data) が書き込み可能である。
273 .\"O Linux also knows about, but does not use
279 .\"O The relationship between
283 .\"O is analogous to the relationship between
286 .\"O .BR pselect (2):
288 .\"O .BR pselect (2),
290 .\"O allows an application to safely wait until either a file descriptor
291 .\"O becomes ready or until a signal is caught.
303 を使うと、アプリケーションはファイルディスクリプタの状態変化
304 もしくはシグナルの捕捉を安全に待つことができる。
306 .\"O Other than the difference in the precision of the
308 .\"O argument, the following
317 ready = ppoll(&fds, nfds, timeout_ts, &sigmask);
320 .\"O is equivalent to
322 .\"O executing the following calls:
331 timeout = (timeout_ts == NULL) ? \-1 :
332 (timeout_ts.tv_sec * 1000 + timeout_ts.tv_nsec / 1000000);
333 sigprocmask(SIG_SETMASK, &sigmask, &origmask);
334 ready = poll(&fds, nfds, timeout);
335 sigprocmask(SIG_SETMASK, &origmask, NULL);
338 .\"O See the description of
340 .\"O for an explanation of why
351 .\"O argument is specified as NULL, then
352 .\"O no signal mask manipulation is performed
357 .\"O only in the precision of the
361 引き数に NULL が指定された場合、シグナルマスクの操作は行われない
372 .\"O argument specifies an upper limit on the amount of time that
375 .\"O This argument is a pointer to a structure of the following form:
379 が停止する時間の上限を指定するものである。
380 この引き数には以下の型の構造体へのポインタを指定する。
385 long tv_sec; /* seconds */
386 long tv_nsec; /* nanoseconds */
393 .\"O is specified as NULL, then
395 .\"O can block indefinitely.
400 .\"O .SH "RETURN VALUE"
402 .\"O On success, a positive number is returned; this is
403 .\"O the number of structures which have nonzero
405 .\"O fields (in other words, those descriptors with events or errors reported).
406 .\"O A value of 0 indicates that the call timed out and no file
407 .\"O descriptors were ready.
408 .\"O On error, \-1 is returned, and
410 .\"O is set appropriately.
411 成功した場合は正の数を返す。この数は 0 以外の
413 要素を持つ構造体の数である (別の言い方をすると、これらのディスクリプタ
415 値 0 は、タイムアウトとなり、どのファイルディスクリプタでもイベントが
416 発生しなかったことを示す。エラーの場合は \-1 が返され、
423 .\"O The array given as argument was not contained in the calling program's
425 引き数として指定した配列が、呼び出したプロセスのアドレス空間に
429 .\"O A signal occurred before any requested event; see
431 要求されたイベントのどれかが起こる前にシグナルが発生した。
438 .\"O value exceeds the
439 .\"O .B RLIMIT_NOFILE
447 .\"O There was no space to allocate file descriptor tables.
448 ファイルディスクリプタ・テーブルを確保するためのメモリがない。
453 .\"O system call was introduced in Linux 2.1.23.
456 .\"O library call was introduced in libc 5.4.28
457 .\"O (and provides emulation using
459 .\"O if your kernel does not
464 システムコールは Linux 2.1.23 で導入された。
466 ライブラリ・コールは libc 5.4.28 から導入された
475 .\"O system call was added to Linux in kernel 2.6.16.
478 .\"O library call was added in glibc 2.4.
480 システムコールは カーネル 2.6.16 で Linux に追加された。
482 ライブラリコールは glibc 2.4 に追加された。
483 .\"O .SH "CONFORMING TO"
486 .\"O conforms to POSIX.1-2001.
488 .\"O is Linux-specific.
489 .\"O .\" NetBSD 3.0 has a pollts() which is like Linux ppoll().
491 は POSIX.1-2001 に準拠している。
494 .\" NetBSD 3.0 には pollts() がある。
495 .\" pollts() は Linux ppoll () と同じようなものである。
498 .\"O Some implementations define the nonstandard constant
500 .\"O with the value \-1 for use as a
504 .\"O This constant is not provided in glibc.
505 いくつかの実装では、値 \-1 を持った非標準の定数
512 この定数は glibc では定義されていない。
513 .\"O .SS "LINUX NOTES"
517 .\"O system call modifies its
520 .\"O However, the glibc wrapper function hides this behavior
521 .\"O by using a local variable for the timeout argument that
522 .\"O is passed to the system call.
525 .\"O function does not modify its
533 しかし、glibc のラッパー関数は、システムコールに渡す timeout 引き数
534 としてローカル変数を使うことでこの動作を隠蔽している。
542 .\"O See the discussion of spurious readiness notifications under the
546 の「バグ」の節に書かれている、誤った準備完了通知 (spurious readiness
547 notifications) についての議論を参照のこと。