OSDN Git Service

(split) LDP: Update drafts from ja.po of LDP v3.51
[linuxjm/LDP_man-pages.git] / draft / man2 / select.2
index 39e3050..5905f7c 100644 (file)
@@ -1,8 +1,7 @@
-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
 .\" This manpage is copyright (C) 1992 Drew Eckhardt,
 .\"                 copyright (C) 1995 Michael Shields.
 .\"
+.\" %%%LICENSE_START(VERBATIM)
 .\" Permission is granted to make and distribute verbatim copies of this
 .\" manual provided the copyright notice and this permission notice are
 .\" preserved on all copies.
@@ -22,6 +21,7 @@
 .\"
 .\" Formatted or processed versions of this manual, if unaccompanied by
 .\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
 .\"
 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
 .\" Modified 1995-05-18 by Jim Van Zandt <jrv@vanzandt.mv.com>
 .\" 2005-03-11, mtk, modified pselect() text (it is now a system
 .\"     call in 2.6.16.
 .\"
-.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya all rights reserved.
-.\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
-.\" Modified 2000-03-12, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
-.\" Updated & Modified 2001-06-04, Yuichi SATO <ysato@h4.dion.ne.jp>
-.\" Updated & Modified 2001-07-01, Yuichi SATO
-.\" Updated & Modifedd 2002-01-14, Yuichi SATO
-.\" Updated 2002-09-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
-.\" Updated 2003-01-19, Akihiro MOTOKI
-.\" Updated 2005-03-17, Akihiro MOTOKI
-.\" Updated 2006-04-16, Akihiro MOTOKI, LDP v2.28
-.\" Updated 2006-07-23, Akihiro MOTOKI, LDP v2.36
-.\" Updated 2007-09-08, Akihiro MOTOKI, LDP v2.64
-.\" Updated 2008-08-06, Akihiro MOTOKI, LDP v3.05
+.\"*******************************************************************
 .\"
-.\"WORD:       synchronous             同期させる
-.\"WORD:       multiplexing            多重化
-.\"WORD:       file descriptor         ファイルディスクリプタ
-.\"WORD:       descriptor              記述子
-.\"WORD:       macro                   マクロ
-.\"WORD:       block                   停止(block)
-.\"WORD:       block                   禁止(block)
-.\"WORD:       signal                  シグナル
-.\"WORD:       timeout                 時間切れ(timeout)
-.\"WORD:       portable                移植性のある
+.\" This file was generated with po4a. Translate the source file.
 .\"
-.TH SELECT 2 2010-08-31 "Linux" "Linux Programmer's Manual"
-.\"O .SH NAME
+.\"*******************************************************************
+.TH SELECT 2 2012\-08\-17 Linux "Linux Programmer's Manual"
 .SH 名前
-.\"O select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \-
-.\"O synchronous I/O multiplexing
-select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \- 多重化された I/O の同期をとる
-.\"O .SH SYNOPSIS
+select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \- 同期 I/O の多重化
 .SH 書式
 .nf
-.\"O /* According to POSIX.1-2001 */
-/* POSIX.1-2001 に従う場合 */
+/* POSIX.1\-2001 に従う場合 */
 .br
-.B #include <sys/select.h>
+\fB#include <sys/select.h>\fP
 .sp
-.\"O /* According to earlier standards */
 /* 以前の規格に従う場合 */
 .br
-.B #include <sys/time.h>
+\fB#include <sys/time.h>\fP
 .br
-.B #include <sys/types.h>
+\fB#include <sys/types.h>\fP
 .br
-.B #include <unistd.h>
+\fB#include <unistd.h>\fP
 .sp
-.BI "int select(int " nfds ", fd_set *" readfds ", fd_set *" writefds ,
-.BI "           fd_set *" exceptfds ", struct timeval *" timeout );
+\fBint select(int \fP\fInfds\fP\fB, fd_set *\fP\fIreadfds\fP\fB, fd_set *\fP\fIwritefds\fP\fB,\fP
+\fB           fd_set *\fP\fIexceptfds\fP\fB, struct timeval *\fP\fItimeout\fP\fB);\fP
 .sp
-.BI "void FD_CLR(int " fd ", fd_set *" set );
+\fBvoid FD_CLR(int \fP\fIfd\fP\fB, fd_set *\fP\fIset\fP\fB);\fP
 .br
-.BI "int  FD_ISSET(int " fd ", fd_set *" set );
+\fBint  FD_ISSET(int \fP\fIfd\fP\fB, fd_set *\fP\fIset\fP\fB);\fP
 .br
-.BI "void FD_SET(int " fd ", fd_set *" set );
+\fBvoid FD_SET(int \fP\fIfd\fP\fB, fd_set *\fP\fIset\fP\fB);\fP
 .br
-.BI "void FD_ZERO(fd_set *" set );
+\fBvoid FD_ZERO(fd_set *\fP\fIset\fP\fB);\fP
 .sp
-.B #include <sys/select.h>
+\fB#include <sys/select.h>\fP
 .sp
-.BI "int pselect(int " nfds ", fd_set *" readfds ", fd_set *" writefds ,
-.BI "            fd_set *" exceptfds ", const struct timespec *" timeout ,
-.BI "            const sigset_t *" sigmask );
+\fBint pselect(int \fP\fInfds\fP\fB, fd_set *\fP\fIreadfds\fP\fB, fd_set *\fP\fIwritefds\fP\fB,\fP
+\fB            fd_set *\fP\fIexceptfds\fP\fB, const struct timespec *\fP\fItimeout\fP\fB,\fP
+\fB            const sigset_t *\fP\fIsigmask\fP\fB);\fP
 .fi
 .sp
 .in -4n
-.\"O Feature Test Macro Requirements for glibc (see
-.\"O .BR feature_test_macros (7)):
-glibc 向けの機能検査マクロの要件
-.RB ( feature_test_macros (7)
-参照):
+glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
 .in
 .sp
-.BR pselect ():
-_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
-.\"O .SH DESCRIPTION
+\fBpselect\fP(): _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
 .SH 説明
-.\"O .BR select ()
-.\"O and
-.\"O .BR pselect ()
-.\"O allow a program to monitor multiple file descriptors,
-.\"O waiting until one or more of the file descriptors become "ready"
-.\"O for some class of I/O operation (e.g., input possible).
-.\"O A file descriptor is considered ready if it is possible to
-.\"O perform the corresponding I/O operation (e.g.,
-.\"O .BR read (2))
-.\"O without blocking.
-.BR select ()
-や
-.BR pselect ()
-を使うと、プログラムで複数のファイルディスクリプタを監視し、
-一つ以上のファイルディスクリプタがある種の I/O 操作の
-「ready (準備ができた)」状態 (例えば、読み込み可能になった状態)
-になるまで待つことができる。
-ファイルディスクリプタが ready (準備ができた) とは、
-対応する I/O 操作 (例えば
-.BR read (2)
+\fBselect\fP()  や \fBpselect\fP()  を使うと、プログラムで複数のファイルディスクリプタを監視し、
+一つ以上のファイルディスクリプタがある種の I/O 操作の 「ready (準備ができた)」状態 (例えば、読み込み可能になった状態)
+になるまで待つことができる。 ファイルディスクリプタが ready (準備ができた) とは、 対応する I/O 操作 (例えば \fBread\fP(2)
 など) が停止 (block) なしに実行可能な状態にあることを意味する。
 .PP
-.\"O The operation of
-.\"O .BR select ()
-.\"O and
-.\"O .BR pselect ()
-.\"O is identical, with three differences:
-.BR select ()
-と
-.BR pselect ()
-の動作は同じであるが、以下の 3 点が異なる:
-.TP
+\fBselect\fP()  と \fBpselect\fP()  の動作は同じであるが、以下の 3 点が異なる:
+.TP 
 (i)
-.\"O .BR select ()
-.\"O uses a timeout that is a
-.\"O .I struct timeval
-.\"O (with seconds and microseconds), while
-.\"O .BR pselect ()
-.\"O uses a
-.\"O .I struct timespec
-.\"O (with seconds and nanoseconds).
-.BR select ()
-では、タイムアウト時間の指定に構造体
-.I struct timeval
-(秒・マイクロ秒単位) を用いる。
-一方、
-.BR pselect ()
-関数では、構造体
-.I struct timespec
-(秒・ナノ秒単位) を用いる。
-.TP
+\fBselect\fP()  では、タイムアウト時間の指定に構造体 \fIstruct timeval\fP (秒・マイクロ秒単位) を用いる。 一方、
+\fBpselect\fP()  関数では、構造体 \fIstruct timespec\fP (秒・ナノ秒単位) を用いる。
+.TP 
 (ii)
-.\"O .BR select ()
-.\"O may update the
-.\"O .I timeout
-.\"O argument to indicate how much time was left.
-.\"O .BR pselect ()
-.\"O does not change this argument.
-.BR select ()
-は残り時間を示す
-.I timeout
-引き数を更新することがある。
-.BR pselect ()
-はこの引き数を変更しない。
-.TP
+\fBselect\fP()  は残り時間を示す \fItimeout\fP 引き数を更新することがある。 \fBpselect\fP()  はこの引き数を変更しない。
+.TP 
 (iii)
-.\"O The
-.\"O .BR select ()
-.\"O has no
-.\"O .I sigmask
-.\"O argument, and behaves as
-.\"O .BR pselect ()
-.\"O called with NULL
-.\"O .IR sigmask .
-.BR select ()
-は
-.I sigmask
-引き数を持たない。その動作は
-.I sigmask
-に NULL を指定した場合の
-.BR pselect ()
-と同じである。
+\fBselect\fP()  は \fIsigmask\fP 引き数を持たない。その動作は \fIsigmask\fP に NULL を指定した場合の
+\fBpselect\fP()  と同じである。
 .PP
-.\"O Three independent sets of file descriptors are watched.
-.\"O Those listed in
-.\"O .I readfds
-.\"O will be watched to see if characters become
-.\"O available for reading (more precisely, to see if a read will not
-.\"O block; in particular, a file descriptor is also ready on end-of-file),
-.\"O those in
-.\"O .I writefds
-.\"O will be watched to see if a write will not block, and
-.\"O those in
-.\"O .I exceptfds
-.\"O will be watched for exceptions.
-.\"O On exit, the sets are modified in place
-.\"O to indicate which file descriptors actually changed status.
-.\"O Each of the three file descriptor sets may be specified as NULL
-.\"O if no file descriptors are to be watched for the corresponding class
-.\"O of events.
-3 つの独立したファイルディスクリプタ集合の監視を行う。
-.I readfds
-に入れられたディスクリプタについては、読み込みが可能かどうかを
-監視する (より正確にいうと、停止 (block) なしで読むことができるかを
-調べる。ファイルの終端 (end-of-file) の場合も、
-ファイルディスクリプタは読み込み可能として扱われる)。
-.I writefds
-に入れられたディスクリプタについては、停止せずに書き込みが
-可能かどうかを監視する。
-.I exceptfds
-にあるものについては、例外の監視を行なう。システムコール終了時に、
-どのファイルディスクリプタの状態が実際に変化したか示すために、
-集合の内容が変更される。
-ある種別のイベントを監視したいファイルディスクリプタが一つもない場合には、
-対応するファイルディスクリプタ集合に NULL を指定することができる。
+3 つの独立したファイルディスクリプタ集合の監視を行う。 \fIreadfds\fP に入れられたディスクリプタについては、読み込みが可能かどうかを 監視する
+(より正確にいうと、停止 (block) なしで読むことができるかを 調べる。ファイルの終端 (end\-of\-file) の場合も、
+ファイルディスクリプタは読み込み可能として扱われる)。 \fIwritefds\fP に入れられたディスクリプタについては、停止せずに書き込みが
+可能かどうかを監視する。 \fIexceptfds\fP にあるものについては、例外の監視を行なう。システムコール終了時に、
+どのファイルディスクリプタの状態が実際に変化したか示すために、 集合の内容が変更される。
+ある種別のイベントを監視したいファイルディスクリプタが一つもない場合には、 対応するファイルディスクリプタ集合に NULL を指定することができる。
 .PP
-.\"O Four macros are provided to manipulate the sets.
-集合を操作するために 4 つのマクロが提供されている。
-.\"O .BR FD_ZERO ()
-.\"O clears a set.
-.BR FD_ZERO ()
-は集合を消去する。
-.\"O .BR FD_SET ()
-.\"O and
-.\"O .BR FD_CLR ()
-.\"O respectively add and remove a given file descriptor from a set.
-.BR FD_SET ()
-と
-.BR FD_CLR ()
-はそれぞれ指定したファイルディスクリプタの集合への追加、削除を行う。
-.\"O .BR FD_ISSET ()
-.\"O tests to see if a file descriptor is part of the set;
-.\"O this is useful after
-.\"O .BR select ()
-.\"O returns.
-.BR FD_ISSET ()
-は集合にファイルディスクリプタがあるかどうか調べる; 
-このマクロは
-.BR select ()
-が終了した後に使うと便利である。
+集合を操作するために 4 つのマクロが提供されている。 \fBFD_ZERO\fP()  は集合を消去する。 \fBFD_SET\fP()  と
+\fBFD_CLR\fP()  はそれぞれ指定したファイルディスクリプタの集合への追加、削除を行う。 \fBFD_ISSET\fP()
+は集合にファイルディスクリプタがあるかどうか調べる; このマクロは \fBselect\fP()  が終了した後に使うと便利である。
 .PP
-.\"O .I nfds
-.\"O is the highest-numbered file descriptor in any of the three sets, plus 1.
-.I nfds
-は 3 つの集合に含まれるファイルディスクリプタの最大値に 1 を足したものである。
+\fInfds\fP は 3 つの集合に含まれるファイルディスクリプタの最大値に 1 を足したものである。
 .PP
-.\"O .I timeout
-.\"O is an upper bound on the amount of time elapsed before
-.\"O .BR select ()
-.\"O returns.
-.\"O If both fields of the
-.\"O .I timeval
-.\"O structure are zero, then
-.\"O .BR select ()
-.\"O returns immediately.
-.\"O (This is useful for polling.)
-.\"O If
-.\"O .I timeout
-.\"O is NULL (no timeout),
-.\"O .BR select ()
-.\"O can block indefinitely.
-.I timeout
-は
-.BR select ()
-が復帰するまでの経過時間の上限である。
-.I timeval
-構造体の両方のフィールドが 0 の場合、
-.BR select ()
-はすぐに復帰する
-(この機能はポーリング (polling) を行うのに便利である)。
-.I timeout
-に NULL (タイムアウトなし)
-が指定されると、
-.BR select ()
-は無期限に停止 (block) する。
+\fItimeout\fP 引き数で、ファイルディスクリプタが ready になるのを待って
+\fBselect\fP() が停止する最小の停止時間を指定する
+(この停止時間はシステムクロックの粒度に切り上げられ、
+カーネルのスケジューリング遅延により少しだけ長くなる可能性がある)。
+\fItimeval\fP 構造体の両方のフィールドが 0 の場合、 \fBselect\fP() はすぐに復
+帰する (この機能はポーリング (polling) を行うのに便利である)。
+\fItimeout\fP に NULL (タイムアウトなし) が指定されると、 \fBselect\fP() は無
+期限に停止 (block) する。
 .PP
-.\"O .I sigmask
-.\"O is a pointer to a signal mask (see
-.\"O .BR sigprocmask (2));
-.\"O if it is not NULL, then
-.\"O .BR pselect ()
-.\"O first replaces the current signal mask by the one pointed to by
-.\"O .IR sigmask ,
-.\"O then does the "select" function, and then restores the original
-.\"O signal mask.
-.I sigmask
-は、シグナルマスク
-.RB ( sigprocmask (2)
-を参照) へのポインタである。
-.I sigmask
-が NULL でない場合、
-.BR pselect ()
-は
-.I sigmask
-が指しているシグナルマスクで現在のシグナルマスクを置き換えてから、
-"select" 関数を実行し、
-終了後にシグナルマスクを元のシグナルマスクに戻す。
+\fIsigmask\fP は、シグナルマスク (\fBsigprocmask\fP(2)  を参照) へのポインタである。 \fIsigmask\fP が NULL
+でない場合、 \fBpselect\fP()  は \fIsigmask\fP が指しているシグナルマスクで現在のシグナルマスクを置き換えてから、 "select"
+関数を実行し、 終了後にシグナルマスクを元のシグナルマスクに戻す。
 .PP
-.\"O Other than the difference in the precision of the
-.\"O .I timeout
-.\"O argument, the following
-.\"O .BR pselect ()
-.\"O call:
-.I timeout
-引き数の精度の違いを除くと、以下の
-.BR pselect ()
-の呼び出しは、
+\fItimeout\fP 引き数の精度の違いを除くと、以下の \fBpselect\fP()  の呼び出しは、
 .nf
 
     ready = pselect(nfds, &readfds, &writefds, &exceptfds,
                     timeout, &sigmask);
 
 .fi
-.\"O is equivalent to
-.\"O .I atomically
-.\"O executing the following calls:
-次のコールを
-.I atomic
-に実行するのと等価である。
+次のコールを \fIatomic\fP に実行するのと等価である。
 .nf
 
     sigset_t origmask;
 
-    sigprocmask(SIG_SETMASK, &sigmask, &origmask);
+    pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
     ready = select(nfds, &readfds, &writefds, &exceptfds, timeout);
-    sigprocmask(SIG_SETMASK, &origmask, NULL);
+    pthread_sigmask(SIG_SETMASK, &origmask, NULL);
 .fi
 .PP
-.\"O The reason that
-.\"O .BR pselect ()
-.\"O is needed is that if one wants to wait for either a signal
-.\"O or for a file descriptor to become ready, then
-.\"O an atomic test is needed to prevent race conditions.
-.\"O (Suppose the signal handler sets a global flag and
-.\"O returns.
-.\"O Then a test of this global flag followed by a call of
-.\"O .BR select ()
-.\"O could hang indefinitely if the signal arrived just after the test
-.\"O but just before the call.
-.BR pselect ()
-が必要になる理由は、シグナルやファイルディスクリプタの状態変化を
-待ちたいときには、競合状態を避けるために atomic なテストが必要になる
-からである。
-(シグナルハンドラが大域フラグを設定して戻る場合を考えてみよう。
-この大域フラグのテストに続けて
-.BR select ()
-を呼び出すと、
-シグナルがテストの直後かつ呼び出しの直前に届いた時には
-.BR select ()
-は永久にハングしてしまうかもしれない。
-.\"O By contrast,
-.\"O .BR pselect ()
-.\"O allows one to first block signals, handle the signals that have come in,
-.\"O then call
-.\"O .BR pselect ()
-.\"O with the desired
-.\"O .IR sigmask ,
-.\"O avoiding the race.)
-一方、
-.BR pselect ()
-を使うと、まずシグナルを禁止 (block) して、入ってくるシグナルを操作し、
-望みの
-.I sigmask
-で
-.BR pselect ()
-を呼び出すことで、前記の競合を避けることができる。)
-.\"O .SS "The timeout"
+\fBpselect\fP()  が必要になる理由は、シグナルやファイルディスクリプタの状態変化を 待ちたいときには、競合状態を避けるために atomic
+なテストが必要になる からである。 (シグナルハンドラが大域フラグを設定して戻る場合を考えてみよう。 この大域フラグのテストに続けて
+\fBselect\fP()  を呼び出すと、 シグナルがテストの直後かつ呼び出しの直前に届いた時には \fBselect\fP()
+は永久にハングしてしまうかもしれない。 一方、 \fBpselect\fP()  を使うと、まずシグナルを禁止 (block)
+して、入ってくるシグナルを操作し、 望みの \fIsigmask\fP で \fBpselect\fP()  を呼び出すことで、前記の競合を避けることができる。)
 .SS タイムアウト
-.\"O The time structures involved are defined in
-.\"O .I <sys/time.h>
-.\"O and look like
-これらの関数で使用される時間関連の構造体は、
-.I <sys/time.h>
-で以下のように定義されている。
+これらの関数で使用される時間関連の構造体は、 \fI<sys/time.h>\fP で
 
-.\"O .in +4n
-.\"O .nf
-.\"O struct timeval {
-.\"O     long    tv_sec;         /* seconds */
-.\"O     long    tv_usec;        /* microseconds */
-.\"O };
-.\"O .fi
-.\"O .in
 .in +4n
 .nf
 struct timeval {
@@ -405,16 +159,8 @@ struct timeval {
 .fi
 .in
 
-.\"O and
-.\"O
-.\"O .in +4n
-.\"O .nf
-.\"O struct timespec {
-.\"O     long    tv_sec;         /* seconds */
-.\"O     long    tv_nsec;        /* nanoseconds */
-.\"O };
-.\"O .fi
-.\"O .in
+や
+
 .in +4n
 .nf
 struct timespec {
@@ -424,242 +170,55 @@ struct timespec {
 .fi
 .in
 
-.\"O (However, see below on the POSIX.1-2001 versions.)
-(POSIX.1-2001 での定義については下記の「注意」を参照)
+のように定義されている。 (POSIX.1\-2001 での定義については下記の「注意」を参照)
 .PP
-.\"O Some code calls
-.\"O .BR select ()
-.\"O with all three sets empty,
-.\"O .I nfds
-.\"O zero, and a non-NULL
-.\"O .I timeout
-.\"O as a fairly portable way to sleep with subsecond precision.
-秒単位以下の精度でスリープを実現する
-移植性の高い方法として、
-3 つの集合全てを空、
-.I nfds
-を 0 、
-.I timeout
-を NULL でない値に設定して
-.BR select ()
-を呼び出すという方法を使っているコードもある。
+秒単位以下の精度でスリープを実現する 移植性の高い方法として、 3 つの集合全てを空、 \fInfds\fP を 0 、 \fItimeout\fP を NULL
+でない値に設定して \fBselect\fP()  を呼び出すという方法を使っているコードもある。
 .PP
-.\"O On Linux,
-.\"O .BR select ()
-.\"O modifies
-.\"O .I timeout
-.\"O to reflect the amount of time not slept; most other implementations
-.\"O do not do this.
-.\"O (POSIX.1-2001 permits either behavior.)
-.\"O This causes problems both when Linux code which reads
-.\"O .I timeout
-.\"O is ported to other operating systems, and when code is ported to Linux
-.\"O that reuses a \fIstruct timeval\fP for multiple
-.\"O .BR select ()s
-.\"O in a loop without reinitializing it.
-.\"O Consider
-.\"O .I timeout
-.\"O to be undefined after
-.\"O .BR select ()
-.\"O returns.
-Linux では、
-.BR select ()
-は
-.I timeout
-を変更し、残りの停止時間を反映するようになっているが、
-他のほとんどの実装ではこのようになっていない
-(POSIX.1-2001 はどちらの動作も認めている)。
-このため、
-.I timeout
-を参照している Linux のコードを他のオペレーティング・システムへ
-移植する場合、問題が起こる。
-また、ループの中で \fItimeval\fP 構造体を初期化せずにそのまま再利用して
-.BR select ()
-を複数回行なっているコードを Linux へ移植する場合にも、問題が起こる。
-.BR select ()
-から復帰した後は
-.I timeout
-は未定義であると考えるべきである。
-.\"O .\" .PP - it is rumored that:
-.\"O .\" On BSD, when a timeout occurs, the file descriptor bits are not changed.
-.\"O .\" - it is certainly true that:
-.\"O .\" Linux follows SUSv2 and sets the bit masks to zero upon a timeout.
-.\" .PP
-.\" 「BSD ではタイムアウトが起こっても、
-.\" ファイルディスクリプタビットは変わらない」と聞いたことがある。
-.\" 「Linux は SUSv2 に従っており、
-.\" タイムアウトの際にはビットマスクを 0 にする」というのは確かに事実である。
-.\"O .SH "RETURN VALUE"
+.\" .PP - it is rumored that:
+.\" On BSD, when a timeout occurs, the file descriptor bits are not changed.
+.\" - it is certainly true that:
+.\" Linux follows SUSv2 and sets the bit masks to zero upon a timeout.
+Linux では、 \fBselect\fP()  は \fItimeout\fP を変更し、残りの停止時間を反映するようになっているが、
+他のほとんどの実装ではこのようになっていない (POSIX.1\-2001 はどちらの動作も認めている)。 このため、 \fItimeout\fP
+を参照している Linux のコードを他のオペレーティング・システムへ 移植する場合、問題が起こる。 また、ループの中で \fItimeval\fP
+構造体を初期化せずにそのまま再利用して \fBselect\fP()  を複数回行なっているコードを Linux へ移植する場合にも、問題が起こる。
+\fBselect\fP()  から復帰した後は \fItimeout\fP は未定義であると考えるべきである。
 .SH 返り値
-.\"O On success,
-.\"O .BR select ()
-.\"O and
-.\"O .BR pselect ()
-.\"O return the number of file descriptors contained in the three returned
-.\"O descriptor sets (that is, the total number of bits that are set in
-.\"O .IR readfds ,
-.\"O .IR writefds ,
-.\"O .IR exceptfds )
-.\"O which may be zero if the timeout expires before anything interesting happens.
-成功した場合、
-.BR select ()
-と
-.BR pselect ()
-は更新された 3 つのディスクリプタ集合に含まれている
-ファイルディスクリプタの数 (つまり、
-.IR readfds ,
-.IR writefds ,
-.I exceptfds
-中の 1 になっているビットの総数) を返す。
-何も起こらずに時間切れになった場合、
-ディスクリプタの数は 0 になることもある。
-.\"O On error, \-1 is returned, and
-.\"O .I errno
-.\"O is set appropriately; the sets and
-.\"O .I timeout
-.\"O become undefined, so do not
-.\"O rely on their contents after an error.
-エラーならば \-1 を返し、
-.I errno
-に適切な値が設定される; 集合と
-.I timeout
-は未定義となるので、エラーが起こった後はそれらの内容を信頼してはならない。
-.\"O .SH ERRORS
+成功した場合、 \fBselect\fP()  と \fBpselect\fP()  は更新された 3 つのディスクリプタ集合に含まれている
+ファイルディスクリプタの数 (つまり、 \fIreadfds\fP, \fIwritefds\fP, \fIexceptfds\fP 中の 1 になっているビットの総数)
+を返す。 何も起こらずに時間切れになった場合、 ディスクリプタの数は 0 になることもある。 エラーならば \-1 を返し、 \fIerrno\fP
+に適切な値が設定される; 集合と \fItimeout\fP は未定義となるので、エラーが起こった後はそれらの内容を信頼してはならない。
 .SH エラー
-.TP
-.B EBADF
-.\"O An invalid file descriptor was given in one of the sets.
-.\"O (Perhaps a file descriptor that was already closed,
-.\"O or one on which an error has occurred.)
-いずれかの集合に無効なファイルディスクリプタが指定された
-(おそらくは、すでにクローズされたファイルディスクリプタか、
+.TP 
+\fBEBADF\fP
+いずれかの集合に無効なファイルディスクリプタが指定された (おそらくは、すでにクローズされたファイルディスクリプタか、
 エラーが発生したファイルディスクリプタが指定された)。
-.TP
-.B EINTR
-.\"O A signal was caught; see
-.\"O .BR signal (7).
+.TP 
+\fBEINTR\fP
 シグナルを受信した。
-.TP
-.B EINVAL
-.\"O .I nfds
-.\"O is negative or the value contained within
-.\"O .I timeout
-.\"O is invalid.
-.I n
-が負、または
-.I timeout
-に入っている値が不正である。
-.TP
-.B ENOMEM
-.\"O unable to allocate memory for internal tables.
+.TP 
+\fBEINVAL\fP
+\fIn\fP が負、または \fItimeout\fP に入っている値が不正である。
+.TP 
+\fBENOMEM\fP
 内部テーブルにメモリを割り当てることができなかった。
-.\"O .SH VERSIONS
 .SH バージョン
-.\"O .BR pselect ()
-.\"O was added to Linux in kernel 2.6.16.
-.BR pselect ()
-はカーネル 2.6.16 で Linux に追加された。
-.\"O Prior to this,
-.\"O .BR pselect ()
-.\"O was emulated in glibc (but see BUGS).
-それ以前は、
-.BR pselect ()
-は glibc でエミュレートされていた (「バグ」の章を参照)。
-.\"O .SH "CONFORMING TO"
+\fBpselect\fP()  はカーネル 2.6.16 で Linux に追加された。 それ以前は、 \fBpselect\fP()  は glibc
+でエミュレートされていた (「バグ」の章を参照)。
 .SH 準拠
-.\"O .BR select ()
-.\"O conforms to POSIX.1-2001 and
-.\"O 4.4BSD
-.\"O .RB ( select ()
-.\"O first appeared in 4.2BSD).
-.\"O Generally portable to/from
-.\"O non-BSD systems supporting clones of the BSD socket layer (including
-.\"O System V variants).
-.\"O However, note that the System V variant typically
-.\"O sets the timeout variable before exit, but the BSD variant does not.
-.BR select ()
-は POSIX.1-2001 と 4.4BSD
-.RB ( select ()
-は 4.2BSD で最初に登場した) に準拠する。
-BSD ソケット層のクローンをサポートしている非 BSD システム
-(System V 系も含む) との間でだいたい移植性がある。しかし System V 系では
-たいがい timeout 変数を exit の前にセットするが、
-BSD 系ではそうでないので注意すること。
+\fBselect\fP()  は POSIX.1\-2001 と 4.4BSD (\fBselect\fP()  は 4.2BSD で最初に登場した) に準拠する。
+BSD ソケット層のクローンをサポートしている非 BSD システム (System V 系も含む) との間でだいたい移植性がある。しかし System
+V 系では たいがい timeout 変数を exit の前にセットするが、 BSD 系ではそうでないので注意すること。
 .PP
-.\"O .BR pselect ()
-.\"O is defined in POSIX.1g, and in
-.\"O POSIX.1-2001.
-.BR pselect ()
-は POSIX.1g と POSIX.1-2001 で定義されている。
-.\"O .SH NOTES
+\fBpselect\fP()  は POSIX.1g と POSIX.1\-2001 で定義されている。
 .SH 注意
-.\"O An
-.\"O .I fd_set
-.\"O is a fixed size buffer.
-.\"O Executing
-.\"O .BR FD_CLR ()
-.\"O or
-.\"O .BR FD_SET ()
-.\"O with a value of
-.\"O .I fd
-.\"O that is negative or is equal to or larger than
-.\"O .B FD_SETSIZE
-.\"O will result
-.\"O in undefined behavior.
-.\"O Moreover, POSIX requires
-.\"O .I fd
-.\"O to be a valid file descriptor.
-.I fd_set
-は固定サイズのバッファである。
-負や
-.B FD_SETSIZE
-以上の値を持つ
-.I fd
-に対して
-.BR FD_CLR ()
-や
-.BR FD_SET ()
-を実行した場合、
-どのような動作をするかは定義されていない。
-また、 POSIX では
-.I fd
+\fIfd_set\fP は固定サイズのバッファである。 負や \fBFD_SETSIZE\fP 以上の値を持つ \fIfd\fP に対して \fBFD_CLR\fP()  や
+\fBFD_SET\fP()  を実行した場合、 どのような動作をするかは定義されていない。 また、 POSIX では \fIfd\fP
 は有効なファイルディスクリプタでなければならないと規定されている。
 
-.\"O Concerning the types involved, the classical situation is that
-.\"O the two fields of a
-.\"O .I timeval
-.\"O structure are typed as
-.\"O .I long
-.\"O (as shown above), and the structure is defined in
-.\"O .IR <sys/time.h> .
-型宣言に関しては、昔ながらの状況では
-.I timeval
-構造体の 2 つのフィールドは
-(上記のように) 両方とも
-.I long
-型であり、構造体は
-.I <sys/time.h>
-で定義されている。
-.\"O The POSIX.1-2001 situation is
-.\"O
-.\"O .in +4n
-.\"O .nf
-.\"O struct timeval {
-.\"O     time_t         tv_sec;     /* seconds */
-.\"O     suseconds_t    tv_usec;    /* microseconds */
-.\"O };
-.\"O .fi
-.\"O .in
-.\"O
-.\"O where the structure is defined in
-.\"O .I <sys/select.h>
-.\"O and the data types
-.\"O .I time_t
-.\"O and
-.\"O .I suseconds_t
-.\"O are defined in
-.\"O .IR <sys/types.h> .
-POSIX.1-2001 の下では、以下のようになっている。
+型宣言に関しては、昔ながらの状況では \fItimeval\fP 構造体の 2 つのフィールドは (上記のように) 両方とも \fIlong\fP
+型であり、構造体は \fI<sys/time.h>\fP で定義されている。 POSIX.1\-2001 の下では、以下のようになっている。
 
 .in +4n
 .nf
@@ -670,208 +229,84 @@ struct timeval {
 .fi
 .in
 
-この構造体は
-.I <sys/select.h>
-で定義されており、データ型
-.I time_t
-と
-.I suseconds_t
-は
-.I <sys/types.h>
-で定義されている。
+この構造体は \fI<sys/select.h>\fP で定義されており、データ型 \fItime_t\fP と \fIsuseconds_t\fP は
+\fI<sys/types.h>\fP で定義されている。
 .LP
-.\"O Concerning prototypes, the classical situation is that one should
-.\"O include
-.\"O .I <time.h>
-.\"O for
-.\"O .BR select ().
-プロトタイプに関しては、昔ながらの状況で
-.BR select ()
-を使いたい場合は、
-.I <time.h>
-をインクルードすればよい。
-.\"O The POSIX.1-2001 situation is that one should include
-.\"O .I <sys/select.h>
-.\"O for
-.\"O .BR select ()
-.\"O and
-.\"O .BR pselect ().
-POSIX.1-2001 の環境で
-.BR select ()
-と
-.BR pselect ()
-を使いたい場合は、
-.I <sys/select.h>
-をインクルードすればよい。
+プロトタイプに関しては、昔ながらの状況で \fBselect\fP()  を使いたい場合は、 \fI<time.h>\fP
+をインクルードすればよい。 POSIX.1\-2001 の環境で \fBselect\fP()  と \fBpselect\fP()  を使いたい場合は、
+\fI<sys/select.h>\fP をインクルードすればよい。
 
-.\"O Libc4 and libc5 do not have a
-.\"O .I <sys/select.h>
-.\"O header; under glibc 2.0 and later this header exists.
-ヘッダファイル
-.I <sys/select.h>
-は libc4 と libc5 にはなく、glibc 2.0 以降に存在する。
-.\"O Under glibc 2.0 it unconditionally gives the wrong prototype for
-.\"O .BR pselect ().
-.\"O Under glibc 2.1 to 2.2.1 it gives
-.\"O .BR pselect ()
-.\"O when
-.\"O .B _GNU_SOURCE
-.\"O is defined.
-.\"O Since glibc 2.2.2 the requirements are as shown in the SYNOPSIS.
-悪いことに glibc 2.0 以前では
-.BR pselect ()
-のプロトタイプが間違っている。
-glibc 2.1 から 2.2.1 では
-.B _GNU_SOURCE
-が定義されている場合に、
-.BR pselect ()
-が提供される。
-glibc 2.2.2 以降では、
-.BR pselect ()
-を使用するには、「書式」に記載された要件を満たす必要がある。
-.\"O .SS "LINUX NOTES"
+ヘッダファイル \fI<sys/select.h>\fP は libc4 と libc5 にはなく、glibc 2.0 以降に存在する。
+悪いことに glibc 2.0 以前では \fBpselect\fP()  のプロトタイプが間違っている。 glibc 2.1 から 2.2.1 では
+\fB_GNU_SOURCE\fP が定義されている場合に、 \fBpselect\fP()  が提供される。 glibc 2.2.2 以降では、
+\fBpselect\fP()  を使用するには、「書式」に記載された要件を満たす必要がある。
+.SS "Multithreaded applications"
+If a file descriptor being monitored by \fBselect\fP()  is closed in another
+thread, the result is unspecified.  On some UNIX systems, \fBselect\fP()
+unblocks and returns, with an indication that the file descriptor is ready
+(a subsequent I/O operation will likely fail with an error, unless another
+the file descriptor reopened between the time \fBselect\fP()  returned and the
+I/O operations was performed).  On Linux (and some other systems), closing
+the file descriptor in another thread has no effect on \fBselect\fP().  In
+summary, any application that relies on a particular behavior in this
+scenario must be considered buggy.
 .SS "Linux での注意"
-.\"O The Linux
-.\"O .BR pselect ()
-.\"O system call modifies its
-.\"O .I timeout
-.\"O argument.
-Linux の
-.BR pselect ()
-システムコールは
-.I timeout
-引き数を変更する。
-.\"O However, the glibc wrapper function hides this behavior
-.\"O by using a local variable for the timeout argument that
-.\"O is passed to the system call.
-.\"O Thus, the glibc
-.\"O .BR pselect ()
-.\"O function does not modify its timeout argument;
-.\"O this is the behavior required by POSIX.1-2001.
-しかし、 glibc のラッパー関数は、システムコールに渡す timeout 引き数
-としてローカル変数を使うことでこの動作を隠蔽している。
-このため、glibc の
-.BR pselect ()
-関数は timeout 引き数を変更しない。
-これが POSIX.1-2001 が要求している動作である。
-.\"O .SH BUGS
+このページで説明している \fBpselect\fP() のインターフェースは、glibc に
+実装されているものである。内部で呼び出される Linux のシステムコールは
+\fBpselect6\fP() という名前である。このシステムコールは glibc のラッパー
+関数とは少し違った動作をする。
+
+Linux の \fBpselect6\fP() システムコールは \fItimeout\fP 引き数を変更する。
+しかし、glibc のラッパー関数は、システムコールに渡す timeout 引き数と
+してローカル変数を使うことでこの動作を隠蔽している。このため、glibc の
+\fBpselect\fP() 関数は \fItimeout\fP 引き数を変更しない。
+これが POSIX.1\-2001 が要求している動作である。
+
+\fBpselect6\fP() システムコールの最後の引き数は \fIsigset_t\ *\fP 型の
+ポインタではなく、以下に示す構造体である。
+.in +4
+.nf
+
+struct {
+    const sigset_t *ss;     /* シグナル集合へのポインタ */
+    size_t          ss_len; /* 'ss' が指すオブジェクトのサイズ
+                               (バイト数) */
+};
+
+.fi
+.in
+このようにすることで、ほとんどのアーキテクチャがサポートしている
+システムコールの引き数が最大で 6 個という事実を満たしつつ、
+\fBpselect6\fP() システムコールがシグナル集合へのポインタとシグナル集合
+のサイズの両方を取得することができるのである。
 .SH バグ
-.\"O Glibc 2.0 provided a version of
-.\"O .BR pselect ()
-.\"O that did not take a
-.\"O .I sigmask
-.\"O argument.
-glibc 2.0 では、
-.I sigmask
-引き数を取らないバージョンの
-.BR pselect ()
-が提供されていた。
+glibc 2.0 では、 \fIsigmask\fP 引き数を取らないバージョンの \fBpselect\fP()  が提供されていた。
 
-.\"O Starting with version 2.1, glibc provided an emulation of
-.\"O .BR pselect ()
-.\"O that was implemented using
-.\"O .BR sigprocmask (2)
-.\"O and
-.\"O .BR select ().
-.\"O This implementation remained vulnerable to the very race condition that
-.\"O .BR pselect ()
-.\"O was designed to prevent.
-バージョン 2.1 以降の glibc では、
-.BR pselect ()
-は
-.BR sigprocmask (2)
-と
-.BR select ()
-を使ってエミュレートされていた。
-この実装にはきわどい競合条件において脆弱性が残っていた。
-この競合条件における問題を防止するために
-.BR pselect ()
-は設計されたのである。
-.\"O Modern versions of glibc use the (race-free)
-.\"O .BR pselect ()
-.\"O system call on kernels where it is provided.
-最近のバージョンの glibc では、カーネルがサポートしている場合には、
-(競合が起こらない)
-.BR pselect ()
-システムコールが使用される。
+バージョン 2.1 以降の glibc では、 \fBpselect\fP()  は \fBsigprocmask\fP(2)  と \fBselect\fP()
+を使ってエミュレートされていた。 この実装にはきわどい競合条件において脆弱性が残っていた。 この競合条件における問題を防止するために
+\fBpselect\fP()  は設計されたのである。 最近のバージョンの glibc では、カーネルがサポートしている場合には、 (競合が起こらない)
+\fBpselect\fP()  システムコールが使用される。
 
-.\"O On systems that lack
-.\"O .BR pselect (),
-.\"O reliable (and more portable) signal trapping can be achieved
-.\"O using the self-pipe trick
-.\"O (where a signal handler writes a byte to a pipe whose other end
-.\"O is monitored by
-.\"O .BR select ()
-.\"O in the main program.)
-.BR pselect ()
-がないシステムにおいて、
-シグナルの捕捉を信頼性があり (移植性も高い) 方法で行うには、
-自己パイプ (self-pipe) という技を使うとよい (シグナルハンドラはパイプへ
-1 バイトのデータを書き込み、同じパイプのもう一端をメインプログラムの
-.BR select ()
-で監視するという方法である)。
+\fBpselect\fP() がないシステムにおいて、シグナルの捕捉を信頼性があり (移植
+性も高い) 方法で行うには、 自己パイプ (self\-pipe) という技を使うとよい。
+この方法では、シグナルハンドラはパイプへ 1 バイトのデータを書き込み、
+同じパイプのもう一端をメインプログラムの \fBselect\fP() で監視する (一杯に
+なったパイプへの書き込みや空のパイプから読み出しを行った際に起こるであ
+ろう停止 (blocking) を避けるためには、パイプへの読み書きの際には 非停止
+(nonblocking) I/O を使用するとよい)。
 
-.\"O Under Linux,
-.\"O .BR select ()
-.\"O may report a socket file descriptor as "ready for reading", while
-.\"O nevertheless a subsequent read blocks.
-.\"O This could for example
-.\"O happen when data has arrived but upon examination has wrong
-.\"O checksum and is discarded.
-.\"O There may be other circumstances
-.\"O in which a file descriptor is spuriously reported as ready.
-.\"O .\" Stevens discusses a case where accept can block after select
-.\"O .\" returns successfully because of an intervening RST from the client.
-.\"O Thus it may be safer to use
-.\"O .B O_NONBLOCK
-.\"O on sockets that should not block.
-Linux では、
-.BR select ()
-がソケットファイルディスクリプタで "読み込みの準備ができた" と報告した場合でも、
-この後で read を行うと停止 (block) することがある。このような状況は、
-例えば、データが到着したが、検査でチェックサム異常が見つかり廃棄された時
-などに起こりえる。他にもファイルディスクリプタが準備できたと間違って
-報告される状況が起こるかもしれない。
-.\" Stevens が挙げたのは、select が成功して復帰してから accept が
-.\" 呼ばれるまでの間に、クライアントから RST が送られると、
-.\" accept が停止する場合である。
-したがって、停止すべきではないソケットに対しては
-.B O_NONBLOCK
-を使うとより安全であろう。
-.\"O .\" Maybe the kernel should have returned EIO in such a situation?
-.\" 多分、このような状況ではカーネルは EIO を返してしまう?
+.\" Stevens discusses a case where accept can block after select
+.\" returns successfully because of an intervening RST from the client.
+.\" Maybe the kernel should have returned EIO in such a situation?
+Linux では、 \fBselect\fP()  がソケットファイルディスクリプタで "読み込みの準備ができた" と報告した場合でも、 この後で read
+を行うと停止 (block) することがある。このような状況は、 例えば、データが到着したが、検査でチェックサム異常が見つかり廃棄された時
+などに起こりえる。他にもファイルディスクリプタが準備できたと間違って 報告される状況が起こるかもしれない。
+したがって、停止すべきではないソケットに対しては \fBO_NONBLOCK\fP を使うとより安全であろう。
 
-.\"O On Linux,
-.\"O .BR select ()
-.\"O also modifies
-.\"O .I timeout
-.\"O if the call is interrupted by a signal handler (i.e., the
-.\"O .B EINTR
-.\"O error return).
-.\"O This is not permitted by POSIX.1-2001.
-.\"O The Linux
-.\"O .BR pselect ()
-.\"O system call has the same behavior,
-.\"O but the glibc wrapper hides this behavior by internally copying the
-.\"O .I timeout
-.\"O to a local variable and passing that variable to the system call.
-Linux では、
-.BR select ()
-がシグナルハンドラにより割り込まれた場合 (つまり
-.B EINTR
-エラーが返る場合)、
-.I timeout
-も変更する。
-これは POSIX.1-2001 では認められていない挙動である。
-Linux の
-.BR pselect ()
-システムコールも同じ挙動をするが、
-glibc のラッパー関数がこの挙動を隠蔽している。
-具体的には、glibc のラッパー関数の内部で、
-.I timeout
-をローカル変数にコピーし、
-このローカル変数をシステムコールに渡している。
-.\"O .SH EXAMPLE
+Linux では、 \fBselect\fP()  がシグナルハンドラにより割り込まれた場合 (つまり \fBEINTR\fP エラーが返る場合)、
+\fItimeout\fP も変更する。 これは POSIX.1\-2001 では認められていない挙動である。 Linux の \fBpselect\fP()
+システムコールも同じ挙動をするが、 glibc のラッパー関数がこの挙動を隠蔽している。 具体的には、glibc のラッパー関数の内部で、
+\fItimeout\fP をローカル変数にコピーし、 このローカル変数をシステムコールに渡している。
 .SH 例
 .nf
 #include <stdio.h>
@@ -880,34 +315,6 @@ glibc のラッパー関数がこの挙動を隠蔽している。
 #include <sys/types.h>
 #include <unistd.h>
 
-.\"O int
-.\"O main(void)
-.\"O {
-.\"O     fd_set rfds;
-.\"O     struct timeval tv;
-.\"O     int retval;
-.\"O
-.\"O     /* Watch stdin (fd 0) to see when it has input. */
-.\"O     FD_ZERO(&rfds);
-.\"O     FD_SET(0, &rfds);
-.\"O
-.\"O     /* Wait up to five seconds. */
-.\"O     tv.tv_sec = 5;
-.\"O     tv.tv_usec = 0;
-.\"O
-.\"O     retval = select(1, &rfds, NULL, NULL, &tv);
-.\"O     /* Don't rely on the value of tv now! */
-.\"O
-.\"O     if (retval == \-1)
-.\"O         perror("select()");
-.\"O     else if (retval)
-.\"O         printf("Data is available now.\\n");
-.\"O         /* FD_ISSET(0, &rfds) will be true. */
-.\"O     else
-.\"O         printf("No data within five seconds.\\n");
-.\"O
-.\"O     exit(EXIT_SUCCESS);
-.\"O }
 int
 main(void)
 {
@@ -929,31 +336,20 @@ main(void)
     if (retval == \-1)
        perror("select()");
     else if (retval)
-        printf("今、データが取得できました。\\n");
+        printf("今、データが取得できました。\en");
         /* FD_ISSET(0, &rfds) が true になる。*/
     else
-        printf("5 秒以内にデータが入力されませんでした。\\n");
+        printf("5 秒以内にデータが入力されませんでした。\en");
 
     exit(EXIT_SUCCESS);
 }
 .fi
-.\"O .SH "SEE ALSO"
 .SH 関連項目
-.\"O For a tutorial with discussion and examples, see
-.\"O .BR select_tut (2).
-考察と使用例の書かれたチュートリアルとして、
-.BR select_tut (2)
-がある。
-.LP
-.\"O For vaguely related stuff, see
-関係がありそうなものを挙げておく:
-.BR accept (2),
-.BR connect (2),
-.BR poll (2),
-.BR read (2),
-.BR recv (2),
-.BR send (2),
-.BR sigprocmask (2),
-.BR write (2),
-.BR epoll (7),
-.BR time (7)
+\fBaccept\fP(2), \fBconnect\fP(2), \fBpoll\fP(2), \fBread\fP(2), \fBrecv\fP(2), \fBsend\fP(2),
+\fBsigprocmask\fP(2), \fBwrite\fP(2), \fBepoll\fP(7), \fBtime\fP(7)
+
+考察と使用例の書かれたチュートリアルとして、 \fBselect_tut\fP(2)  がある。
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.51 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。