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"
45 poll, ppoll \- ファイルディスクリプタにおけるイベントを待つ
50 .BI "int poll(struct pollfd *" fds ", nfds_t " nfds ", int " timeout );
52 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */"
55 .BI "int ppoll(struct pollfd *" fds ", nfds_t " nfds ", "
56 .BI " const struct timespec *" timeout_ts ", const sigset_t *" sigmask );
62 と同様の仕事を行う、つまり、ファイルディスクリプタ集合のいずれか一つが
74 int fd; /* file descriptor */
75 short events; /* requested events */
76 short revents; /* returned events */
88 にはオープンしたファイルのファイルディスクリプタを入れる。
92 要素は入力パラメータで、アプリケーションが興味を持っているイベントの
96 要素は出力パラメータで、実際に起こったイベントがカーネルにより設定される。
110 に指定しても意味がなく、対応した状態が真の場合に
114 どのファイルディスクリプタにも要求したイベントが発生しておらず、
117 はイベントのうちいずれか一つが発生するまで停止 (block) する。
122 が停止する時間の上限を設定するもので、ミリ秒単位で指定する。
124 に負の値を指定すると、タイムアウト時間が無限となる。
129 で返されるビットは \fI<poll.h>\fP で定義されている:
136 読み出し可能な緊急データ (urgent data) がある
137 (例えば、TCP ソケットの帯域外 (out-of-band data) データを受信した場合や、
138 パケットモードの擬似端末のマスタがスレーブ側の変化を見つけたとき)。
141 書き込みが停止 (block) しない状態である。
143 .BR POLLRDHUP " (Linux 2.6.17 以降)"
144 ストリームソケットの他端が、コネクションを close したか、
145 コネクションの書き込み側を shutdown した。
147 (「どの」ヘッダファイルをインクルードするよりも前に)
160 がオープンされていない (出力の場合のみ)。
164 を定義してコンパイルした場合には、以下の定義も行われる。
165 ただし、上記のリストにあるビット以上の情報が得られる訳ではない。
173 優先帯域データ (priority band data) が読み出し可能である
174 (普通は Linux では使用されない)。
175 .\" POLLRDBAND is used in the DECnet protocol.
182 優先帯域データ (priority data) が書き込み可能である。
200 を使うと、アプリケーションはファイルディスクリプタの状態変化
201 もしくはシグナルの捕捉を安全に待つことができる。
209 ready = ppoll(&fds, nfds, timeout_ts, &sigmask);
220 timeout = (timeout_ts == NULL) ? \-1 :
221 (timeout_ts.tv_sec * 1000 + timeout_ts.tv_nsec / 1000000);
222 sigprocmask(SIG_SETMASK, &sigmask, &origmask);
223 ready = poll(&fds, nfds, timeout);
224 sigprocmask(SIG_SETMASK, &origmask, NULL);
234 引き数に NULL が指定された場合、シグナルマスクの操作は行われない
246 が停止する時間の上限を指定するものである。
247 この引き数には以下の型の構造体へのポインタを指定する。
252 long tv_sec; /* seconds */
253 long tv_nsec; /* nanoseconds */
263 成功した場合は正の数を返す。この数は 0 以外の
265 要素を持つ構造体の数である (別の言い方をすると、これらのディスクリプタ
267 値 0 は、タイムアウトとなり、どのファイルディスクリプタでもイベントが
268 発生しなかったことを示す。エラーの場合は \-1 が返され、
274 引き数として指定した配列が、呼び出したプロセスのアドレス空間に
278 要求されたイベントのどれかが起こる前にシグナルが発生した。
289 ファイルディスクリプタ・テーブルを確保するためのメモリがない。
292 システムコールは Linux 2.1.23 で導入された。
294 ライブラリ・コールは libc 5.4.28 から導入された
302 システムコールは カーネル 2.6.16 で Linux に追加された。
304 ライブラリコールは glibc 2.4 に追加された。
307 は POSIX.1-2001 に準拠している。
310 .\" NetBSD 3.0 には pollts() がある。
311 .\" pollts() は Linux ppoll () と同じようなものである。
313 いくつかの実装では、値 \-1 を持った非標準の定数
320 この定数は glibc では定義されていない。
327 しかし、glibc のラッパー関数は、システムコールに渡す timeout 引き数
328 としてローカル変数を使うことでこの動作を隠蔽している。
336 の「バグ」の節に書かれている、誤った準備完了通知 (spurious readiness
337 notifications) についての議論を参照のこと。