]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/select_tut.2
dlerror.3: wfix
[thirdparty/man-pages.git] / man2 / select_tut.2
CommitLineData
fea681da
MK
1.\" This manpage is copyright (C) 2001 Paul Sheer.
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
fea681da
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" very minor changes, aeb
26.\"
c11b1abf 27.\" Modified 5 June 2002, Michael Kerrisk <mtk.manpages@gmail.com>
c8e01c78 28.\" 2006-05-13, mtk, removed much material that is redundant with select.2
c13182ef 29.\" various other changes
7ce9ffda 30.\" 2008-01-26, mtk, substantial changes and rewrites
fea681da 31.\"
aefd6f89 32.TH SELECT_TUT 2 2013-12-30 "Linux" "Linux Programmer's Manual"
fea681da 33.SH NAME
c13182ef 34select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \-
35478399 35synchronous I/O multiplexing
fea681da 36.SH SYNOPSIS
b9208776 37.nf
925b118e 38/* According to POSIX.1-2001, POSIX.1-2008 */
b9208776
MK
39.br
40.B #include <sys/select.h>
41.sp
42/* According to earlier standards */
43.br
fea681da
MK
44.B #include <sys/time.h>
45.br
46.B #include <sys/types.h>
47.br
48.B #include <unistd.h>
49.sp
9f0fb198 50.BI "int select(int " nfds ", fd_set *" readfds ", fd_set *" writefds ,
c1bdeb84 51.BI " fd_set *" exceptfds ", struct timeval *" utimeout );
fea681da 52.sp
b9208776 53.BI "void FD_CLR(int " fd ", fd_set *" set );
fea681da 54.br
b9208776 55.BI "int FD_ISSET(int " fd ", fd_set *" set );
fea681da 56.br
b9208776 57.BI "void FD_SET(int " fd ", fd_set *" set );
fea681da 58.br
b9208776
MK
59.BI "void FD_ZERO(fd_set *" set );
60.sp
b9208776
MK
61.B #include <sys/select.h>
62.sp
9f0fb198 63.BI "int pselect(int " nfds ", fd_set *" readfds ", fd_set *" writefds ,
c1bdeb84 64.BI " fd_set *" exceptfds ", const struct timespec *" ntimeout ,
9f0fb198 65.BI " const sigset_t *" sigmask );
fea681da 66.fi
9f0fb198
MK
67.sp
68.in -4n
69Feature Test Macro Requirements for glibc (see
70.BR feature_test_macros (7)):
71.in
72.sp
73.BR pselect ():
74_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
fea681da 75.SH DESCRIPTION
60a90ecd
MK
76.BR select ()
77(or
78.BR pselect ())
7ce9ffda
MK
79is used to efficiently monitor multiple file descriptors,
80to see if any of them is, or becomes, "ready";
81that is, to see whether I/O becomes possible,
82or an "exceptional condition" has occurred on any of the descriptors.
fea681da 83
7ce9ffda
MK
84Its principal arguments are three "sets" of file descriptors:
85\fIreadfds\fP, \fIwritefds\fP, and \fIexceptfds\fP.
86Each set is declared as type
87.IR fd_set ,
88and its contents can be manipulated with the macros
60a90ecd
MK
89.BR FD_CLR (),
90.BR FD_ISSET (),
91.BR FD_SET (),
92and
93.BR FD_ZERO ().
7ce9ffda
MK
94A newly declared set should first be cleared using
95.BR FD_ZERO ().
60a90ecd
MK
96.BR select ()
97modifies the contents of the sets according to the rules
98described below; after calling
99.BR select ()
7ce9ffda 100you can test if a file descriptor is still present in a set with the
60a90ecd
MK
101.BR FD_ISSET ()
102macro.
103.BR FD_ISSET ()
c7094399 104returns nonzero if a specified file descriptor is present in a set
7ce9ffda 105and zero if it is not.
60a90ecd 106.BR FD_CLR ()
7ce9ffda 107removes a file descriptor from a set.
61b48f93 108.SS Arguments
fea681da
MK
109.TP
110\fIreadfds\fP
111This set is watched to see if data is available for reading from any of
c13182ef 112its file descriptors.
60a90ecd
MK
113After
114.BR select ()
115has returned, \fIreadfds\fP will be
7cbaba90 116cleared of all file descriptors except for those that
7ce9ffda 117are immediately available for reading.
fea681da
MK
118.TP
119\fIwritefds\fP
120This set is watched to see if there is space to write data to any of
c13182ef 121its file descriptors.
60a90ecd
MK
122After
123.BR select ()
124has returned, \fIwritefds\fP will be
7cbaba90 125cleared of all file descriptors except for those that
7ce9ffda 126are immediately available for writing.
fea681da
MK
127.TP
128\fIexceptfds\fP
7ce9ffda
MK
129This set is watched for "exceptional conditions".
130In practice, only one such exceptional condition is common:
131the availability of \fIout-of-band\fP (OOB) data for reading
132from a TCP socket.
60a90ecd 133See
7ce9ffda
MK
134.BR recv (2),
135.BR send (2),
60a90ecd 136and
7ce9ffda
MK
137.BR tcp (7)
138for more details about OOB data.
139(One other less common case where
140.BR select (2)
b218b023 141indicates an exceptional condition occurs with pseudoterminals
7ce9ffda
MK
142in packet mode; see
143.BR tty_ioctl (4).)
60a90ecd
MK
144After
145.BR select ()
146has returned,
fea681da 147\fIexceptfds\fP will be cleared of all file descriptors except for those
7ce9ffda 148for which an exceptional condition has occurred.
fea681da
MK
149.TP
150\fInfds\fP
151This is an integer one more than the maximum of any file descriptor in
c13182ef 152any of the sets.