OSDN Git Service

723c5660ba370ac91eedd0f5e96066b8dd338def
[linuxjm/LDP_man-pages.git] / draft / man2 / poll.2
1 .\" Copyright (C) 1997 Andries Brouwer (aeb@cwi.nl)
2 .\" and Copyright (C) 2006, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
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.
30 .\"
31 .\"*******************************************************************
32 .\"
33 .\" This file was generated with po4a. Translate the source file.
34 .\"
35 .\"*******************************************************************
36 .\"
37 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
38 .\"         all rights reserved.
39 .\" Translated 1997-12-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
40 .\" Updated & Modified 2004-05-22, Yuichi SATO <ysato444@yahoo.co.jp>
41 .\" Updated & Modified 2005-01-03, Yuichi SATO
42 .\" Updated & Modified 2005-10-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
43 .\" Updated 2005-12-05, Akihiro MOTOKI, Catch up to LDP man-pages 2.16
44 .\" Updated 2006-04-16, Akihiro MOTOKI, Catch up to LDP man-pages 2.28
45 .\" Updated 2006-07-23, Akihiro MOTOKI, Catch up to LDP man-pages 2.36
46 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
47 .\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
48 .\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
49 .\"
50 .TH POLL 2 2013\-09\-04 Linux "Linux Programmer's Manual"
51 .SH 名前
52 poll, ppoll \- ファイルディスクリプタにおけるイベントを待つ
53 .SH 書式
54 .nf
55 \fB#include <poll.h>\fP
56 .sp
57 \fBint poll(struct pollfd *\fP\fIfds\fP\fB, nfds_t \fP\fInfds\fP\fB, int \fP\fItimeout\fP\fB);\fP
58 .sp
59 \fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
60 \fB#include <poll.h>\fP
61 .sp
62 \fBint ppoll(struct pollfd *\fP\fIfds\fP\fB, nfds_t \fP\fInfds\fP\fB, \fP
63 \fB        const struct timespec *\fP\fItimeout_ts\fP\fB, const sigset_t *\fP\fIsigmask\fP\fB);\fP
64 .fi
65 .SH 説明
66 \fBpoll\fP()  は \fBselect\fP(2)  と同様の仕事を行う、つまり、ファイルディスクリプタ集合のいずれか一つが I/O
67 を実行可能な状態になるのを待つ。
68
69 監視するファイルディスクリプタ集合は、 \fIfds\fP 引き数で指定する。 \fIfds\fP は、以下の型の構造体の配列である。
70 .in +4n
71 .nf
72
73 struct pollfd {
74     int   fd;         /* file descriptor */
75     short events;     /* requested events */
76     short revents;    /* returned events */
77 };
78 .in
79 .fi
80 .PP
81 \fInfds\fP には、 \fIfds\fP 配列の要素数を指定する。
82
83 \fIfd\fP フィールドには、オープンされたファイルのファイルディスクリプタが入る。
84 このフィールドが負の場合、対応する \fIevents\fP フィールドは無視され、
85 \fIrevents\fP には 0 が返される。(この機能により、一つの \fBpoll\fP() の呼び出しで
86 簡単にあるファイルディスクリプタを無視することができる。
87 単に \fIfd\fP フィールドの符号を反転するだけでよい。)
88
89 構造体の \fIevents\fP 要素は入力パラメータで、
90 ファイルディスクリプタ \fIfd\fP に関して、
91 アプリケーションが興味を持っているイベントのビットマスクを指定する。
92 このフィールドに 0 が指定された場合は、\fIfd\fP の全てのイベントが無視され、
93 \fIrevents\fP には 0 が返される。
94
95 \fIrevents\fP 要素は出力パラメータで、実際に起こったイベントがカーネルにより設定される。 \fIrevents\fP で返されるビット列には、
96 \fIevents\fP で指定したもののどれか、もしくは \fBPOLLERR\fP, \fBPOLLHUP\fP, \fBPOLLNVAL\fP のうちの一つが含まれる
97 (\fBPOLLERR\fP, \fBPOLLHUP\fP, \fBPOLLNVAL\fP の 3つのビットは \fIevents\fP
98 に指定しても意味がなく、対応した状態が真の場合に \fIrevents\fP に設定される)。
99
100 どのファイルディスクリプタにも要求したイベントが発生しておらず、 エラーも起こらない場合、 \fBpoll\fP()
101 はイベントのうちいずれか一つが発生するまで停止 (block) する。
102
103 The \fItimeout\fP argument specifies the number of milliseconds that \fBpoll\fP()
104 should block waiting for a file descriptor to become ready.  This interval
105 will be rounded up to the system clock granularity, and kernel scheduling
106 delays mean that the blocking interval may overrun by a small amount.
107 Specifying a negative value in \fItimeout\fP means an infinite timeout.
108 Specifying a \fItimeout\fP of zero causes \fBpoll\fP()  to return immediately,
109 even if no file descriptors are ready.
110
111 \fIevents\fP に指定したり、 \fIrevents\fP で返されるビットは \fI<poll.h>\fP で定義されている:
112 .RS
113 .TP 
114 \fBPOLLIN\fP
115 読み出し可能なデータがある。
116 .TP 
117 \fBPOLLPRI\fP
118 読み出し可能な緊急データ (urgent data) がある (例えば、TCP ソケットの帯域外 (out\-of\-band data)
119 データを受信した場合や、 パケットモードの擬似端末のマスタがスレーブ側の変化を見つけたとき)。
120 .TP 
121 \fBPOLLOUT\fP
122 書き込みが停止 (block) しない状態である。
123 .TP 
124 \fBPOLLRDHUP\fP (Linux 2.6.17 以降)
125 ストリームソケットの他端が、コネクションを close したか、 コネクションの書き込み側を shutdown した。 この定義を有効にするには、
126 (「どの」ヘッダファイルをインクルードするよりも前に)  \fB_GNU_SOURCE\fP 機能検査マクロを定義しなければならない。
127 .TP 
128 \fBPOLLERR\fP
129 エラー状態 (出力の場合のみ)。
130 .TP 
131 \fBPOLLHUP\fP
132 ハングアップした (出力の場合のみ)。
133 .TP 
134 \fBPOLLNVAL\fP
135 不正な要求: \fIfd\fP がオープンされていない (出力の場合のみ)。
136 .RE
137 .PP
138 \fB_XOPEN_SOURCE\fP を定義してコンパイルした場合には、以下の定義も行われる。
139 ただし、上記のリストにあるビット以上の情報が得られる訳ではない。
140 .RS
141 .TP 
142 \fBPOLLRDNORM\fP
143 \fBPOLLIN\fP と同じ。
144 .TP 
145 \fBPOLLRDBAND\fP
146 .\" POLLRDBAND is used in the DECnet protocol.
147 優先帯域データ (priority band data) が読み出し可能である (普通は Linux では使用されない)。
148 .TP 
149 \fBPOLLWRNORM\fP
150 \fBPOLLOUT\fP と同じ。
151 .TP 
152 \fBPOLLWRBAND\fP
153 優先帯域データ (priority data) が書き込み可能である。
154 .RE
155 .PP
156 Linux では \fBPOLLMSG\fP も定義されているが、使用されていない。
157 .SS ppoll()
158 \fBpoll\fP()  と \fBppoll\fP()  の関係は \fBselect\fP(2)  と \fBpselect\fP(2)  の関係と同じようなものである:
159 \fBpselect\fP(2)  と同様に、 \fBppoll\fP()  を使うと、アプリケーションはファイルディスクリプタの状態変化
160 もしくはシグナルの捕捉を安全に待つことができる。
161 .PP
162 \fItimeout\fP 引き数の精度の違いを除くと、以下の \fBppoll\fP()  の呼び出しは、
163 .nf
164
165     ready = ppoll(&fds, nfds, timeout_ts, &sigmask);
166
167 .fi
168 次の呼び出しを \fIatomic\fP に実行するのと等価である。
169 .nf
170
171     sigset_t origmask;
172     int timeout;
173
174     timeout = (timeout_ts == NULL) ? \-1 :
175               (timeout_ts.tv_sec * 1000 + timeout_ts.tv_nsec / 1000000);
176     sigprocmask(SIG_SETMASK, &sigmask, &origmask);
177     ready = poll(&fds, nfds, timeout);
178     sigprocmask(SIG_SETMASK, &origmask, NULL);
179 .fi
180 .PP
181 なぜ \fBppoll\fP()  が必要なのかについての説明は \fBpselect\fP(2)  の説明を参照のこと。
182
183 \fIsigmask\fP 引き数に NULL が指定された場合、シグナルマスクの操作は行われない (したがって、 \fBppoll\fP()  の
184 \fBpoll\fP()  との違いは \fItimeout\fP 引き数の精度だけとなる)。
185
186 \fItimeout\fP 引き数は \fBppoll\fP()  が停止する時間の上限を指定するものである。
187 この引き数には以下の型の構造体へのポインタを指定する。
188 .in +4n
189 .nf
190
191 struct timespec {
192     long    tv_sec;         /* seconds */
193     long    tv_nsec;        /* nanoseconds */
194 };
195 .fi
196 .in
197
198 \fItimeout_ts\fP に NULL が指定された場合、 \fBppoll\fP は無限に停止することがあり得る。
199 .SH 返り値
200 成功した場合は正の数を返す。この数は 0 以外の \fIrevents\fP 要素を持つ構造体の数である (別の言い方をすると、これらのディスクリプタ
201 にはイベントかエラー報告がある)。 値 0 は、タイムアウトとなり、どのファイルディスクリプタでもイベントが 発生しなかったことを示す。エラーの場合は
202 \-1 が返され、 \fIerrno\fP が適切に設定される。
203 .SH エラー
204 .TP 
205 \fBEFAULT\fP
206 引き数として指定した配列が、呼び出したプロセスのアドレス空間に 含まれていない。
207 .TP 
208 \fBEINTR\fP
209 要求されたイベントのどれかが起こる前にシグナルが発生した。 \fBsignal\fP(7)  参照。
210 .TP 
211 \fBEINVAL\fP
212 \fInfds\fP の値が \fBRLIMIT_NOFILE\fP を超えた。
213 .TP 
214 \fBENOMEM\fP
215 ファイルディスクリプタ・テーブルを確保するためのメモリがない。
216 .SH バージョン
217 .\" library call was introduced in libc 5.4.28
218 \fBpoll\fP() システムコールは Linux 2.1.23 で導入された。
219 このシステムコールが存在しない古いカーネルでは、
220 glibc (や古い Linux libc) は \fBselect\fP(2) を使用して \fBpoll\fP()
221 ラッパー関数のエミュレーションを行う。
222
223 \fBppoll\fP()  システムコールは カーネル 2.6.16 で Linux に追加された。 \fBppoll\fP()  ライブラリコールは glibc
224 2.4 に追加された。
225 .SH 準拠
226 .\" NetBSD 3.0 has a pollts() which is like Linux ppoll().
227 \fBpoll\fP()  は POSIX.1\-2001 に準拠している。 \fBppoll\fP()  は Linux 固有である。
228 .SH 注意
229 いくつかの実装では、値 \-1 を持った非標準の定数 \fBINFTIM\fP が定義されており、 \fBpoll\fP()  の \fItimeout\fP
230 の指定に使用できる。 この定数は glibc では定義されていない。
231
232 \fBpoll\fP() で監視中のファイルディスクリプタが別のスレッドによってクローズされた場合に何が起こるかの議論については、 \fBselect\fP(2)
233 を参照してほしい。
234 .SS "Linux での注意"
235 Linux の \fBppoll\fP()  システムコールは \fItimeout_ts\fP 引き数を変更する。 しかし、glibc
236 のラッパー関数は、システムコールに渡す timeout 引き数 としてローカル変数を使うことでこの動作を隠蔽している。 このため、glibc の
237 \fBppoll\fP()  関数では \fItimeout_ts\fP 引き数は変更されない。
238 .SH バグ
239 \fBselect\fP(2)  の「バグ」の節に書かれている、誤った準備完了通知 (spurious readiness notifications)
240 についての議論を参照のこと。
241 .SH 関連項目
242 \fBrestart_syscall\fP(2), \fBselect\fP(2), \fBselect_tut\fP(2), \fBtime\fP(7)
243 .SH この文書について
244 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
245 である。プロジェクトの説明とバグ報告に関する情報は
246 http://www.kernel.org/doc/man\-pages/ に書かれている。