OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / original / man2 / select.2
index ff78008..d4e546e 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>
@@ -35,7 +35,7 @@
 .\" 2005-03-11, mtk, modified pselect() text (it is now a system
 .\"     call in 2.6.16.
 .\"
-.TH SELECT 2 2012-05-02 "Linux" "Linux Programmer's Manual"
+.TH SELECT 2 2015-01-22 "Linux" "Linux Programmer's Manual"
 .SH NAME
 select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \-
 synchronous I/O multiplexing
@@ -86,15 +86,16 @@ allow a program to monitor multiple file descriptors,
 waiting until one or more of the file descriptors become "ready"
 for some class of I/O operation (e.g., input possible).
 A file descriptor is considered ready if it is possible to
-perform the corresponding I/O operation (e.g.,
-.BR read (2))
-without blocking.
+perform a corresponding I/O operation (e.g.,
+.BR read (2)
+without blocking, or a sufficiently small
+.BR write (2)).
 .PP
 The operation of
 .BR select ()
 and
 .BR pselect ()
-is identical, with three differences:
+is identical, other than these three differences:
 .TP
 (i)
 .BR select ()
@@ -131,8 +132,8 @@ available for reading (more precisely, to see if a read will not
 block; in particular, a file descriptor is also ready on end-of-file),
 those in
 .I writefds
-will be watched to see if a write will not block, and
-those in
+will be watched to see if space is available for write (though a large
+write may still block), and those in
 .I exceptfds
 will be watched for exceptions.
 On exit, the sets are modified in place
@@ -159,12 +160,22 @@ is the highest-numbered file descriptor in any of the three sets, plus 1.
 .PP
 The
 .I timeout
-argument specifies the minimum interval that
+argument specifies the interval that
 .BR select ()
 should block waiting for a file descriptor to become ready.
-(This interval will be rounded up to the system clock granularity,
+The call will block until either:
+.IP * 3
+a file descriptor becomes ready;
+.IP *
+the call is interrupted by a signal handler; or
+.IP *
+the timeout expires.
+.PP
+Note that the
+.I timeout
+interval will be rounded up to the system clock granularity,
 and kernel scheduling delays mean that the blocking interval
-may overrun by a small amount.)
+may overrun by a small amount.
 If both fields of the
 .I timeval
 structure are zero, then
@@ -205,9 +216,9 @@ executing the following calls:
 
     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
 The reason that
@@ -229,7 +240,7 @@ then call
 with the desired
 .IR sigmask ,
 avoiding the race.)
-.SS "The timeout"
+.SS The timeout
 The time structures involved are defined in
 .I <sys/time.h>
 and look like
@@ -286,7 +297,7 @@ returns.
 .\" 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.
-.SH "RETURN VALUE"
+.SH RETURN VALUE
 On success,
 .BR select ()
 and
@@ -299,10 +310,11 @@ descriptor sets (that is, the total number of bits that are set in
 which may be zero if the timeout expires before anything interesting happens.
 On error, \-1 is returned, and
 .I errno
-is set appropriately; the sets and
+is set to indicate the error;
+the file descriptor sets are unmodified,
+and
 .I timeout
-become undefined, so do not
-rely on their contents after an error.
+becomes undefined.
 .SH ERRORS
 .TP
 .B EBADF
@@ -316,7 +328,13 @@ A signal was caught; see
 .TP
 .B EINVAL
 .I nfds
-is negative or the value contained within
+is negative or exceeds the
+.BR RLIMIT_NOFILE
+resource limit (see
+.BR getrlimit (2)).
+.TP
+.B EINVAL
+the value contained within
 .I timeout
 is invalid.
 .TP
@@ -328,7 +346,7 @@ was added to Linux in kernel 2.6.16.
 Prior to this,
 .BR pselect ()
 was emulated in glibc (but see BUGS).
-.SH "CONFORMING TO"
+.SH CONFORMING TO
 .BR select ()
 conforms to POSIX.1-2001 and
 4.4BSD
@@ -336,8 +354,8 @@ conforms to POSIX.1-2001 and
 first appeared in 4.2BSD).
 Generally portable to/from
 non-BSD systems supporting clones of the BSD socket layer (including
-System V variants).
-However, note that the System V variant typically
+System\ V variants).
+However, note that the System\ V variant typically
 sets the timeout variable before exit, but the BSD variant does not.
 .PP
 .BR pselect ()
@@ -400,24 +418,40 @@ for
 and
 .BR pselect ().
 
-Libc4 and libc5 do not have a
+Under glibc 2.0,
 .I <sys/select.h>
-header; under glibc 2.0 and later this header exists.
-Under glibc 2.0 it unconditionally gives the wrong prototype for
+gives the wrong prototype for
 .BR pselect ().
-Under glibc 2.1 to 2.2.1 it gives
+Under glibc 2.1 to 2.2.1, it gives
 .BR pselect ()
 when
 .B _GNU_SOURCE
 is defined.
-Since glibc 2.2.2 the requirements are as shown in the SYNOPSIS.
-.SS "Linux Notes"
+Since glibc 2.2.2, the requirements are as shown in the SYNOPSIS.
+.SS Multithreaded applications
+If a file descriptor being monitored by
+.BR select ()
+is closed in another thread, the result is unspecified.
+On some UNIX systems,
+.BR select ()
+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
+.BR select ()
+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
+.BR select ().
+In summary, any application that relies on a particular behavior
+in this scenario must be considered buggy.
+.\"
+.SS C library/kernel ABI differences
 The
 .BR pselect ()
 interface described in this page is implemented by glibc.
 The underlying Linux system call is named
 .BR pselect6 ().
-This system call has somewhat different behavior from the gibc
+This system call has somewhat different behavior from the glibc
 wrapper function.
 
 The Linux
@@ -436,7 +470,7 @@ argument;
 this is the behavior required by POSIX.1-2001.
 
 The final argument of the
-.BR pselect6()
+.BR pselect6 ()
 system call is not a
 .I "sigset_t\ *"
 pointer, but is instead a structure of the form:
@@ -555,18 +589,27 @@ main(void)
     exit(EXIT_SUCCESS);
 }
 .fi
-.SH "SEE ALSO"
-For a tutorial with discussion and examples, see
-.BR select_tut (2).
-.LP
-For vaguely related stuff, see
+.SH SEE ALSO
 .BR accept (2),
 .BR connect (2),
 .BR poll (2),
 .BR read (2),
 .BR recv (2),
+.BR restart_syscall (2),
 .BR send (2),
 .BR sigprocmask (2),
 .BR write (2),
 .BR epoll (7),
 .BR time (7)
+
+For a tutorial with discussion and examples, see
+.BR select_tut (2).
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.