]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/select_tut.2
ipc.5: Remove old link to svipc.7/sysvipc.7 page
[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.\"
9ba01802 32.TH SELECT_TUT 2 2019-03-06 "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 39.B #include <sys/select.h>
dbfe9c70 40.PP
b9208776 41/* According to earlier standards */
fea681da 42.B #include <sys/time.h>
fea681da 43.B #include <sys/types.h>
fea681da 44.B #include <unistd.h>
68e4db0a 45.PP
9f0fb198 46.BI "int select(int " nfds ", fd_set *" readfds ", fd_set *" writefds ,
c1bdeb84 47.BI " fd_set *" exceptfds ", struct timeval *" utimeout );
68e4db0a 48.PP
b9208776 49.BI "void FD_CLR(int " fd ", fd_set *" set );
b9208776 50.BI "int FD_ISSET(int " fd ", fd_set *" set );
b9208776 51.BI "void FD_SET(int " fd ", fd_set *" set );
b9208776 52.BI "void FD_ZERO(fd_set *" set );
f90f031e 53
b9208776 54.B #include <sys/select.h>
68e4db0a 55.PP
9f0fb198 56.BI "int pselect(int " nfds ", fd_set *" readfds ", fd_set *" writefds ,
c1bdeb84 57.BI " fd_set *" exceptfds ", const struct timespec *" ntimeout ,
9f0fb198 58.BI " const sigset_t *" sigmask );
fea681da 59.fi
68e4db0a 60.PP
9f0fb198
MK
61.in -4n
62Feature Test Macro Requirements for glibc (see
63.BR feature_test_macros (7)):
64.in
68e4db0a 65.PP
9f0fb198 66.BR pselect ():
a446ac0c 67_POSIX_C_SOURCE\ >=\ 200112L
fea681da 68.SH DESCRIPTION
60a90ecd
MK
69.BR select ()
70(or
71.BR pselect ())
7ce9ffda
MK
72is used to efficiently monitor multiple file descriptors,
73to see if any of them is, or becomes, "ready";
74that is, to see whether I/O becomes possible,
d9cb0d7d 75or an "exceptional condition" has occurred on any of the file descriptors.
efeece04 76.PP
7ce9ffda
MK
77Its principal arguments are three "sets" of file descriptors:
78\fIreadfds\fP, \fIwritefds\fP, and \fIexceptfds\fP.
79Each set is declared as type
80.IR fd_set ,
81and its contents can be manipulated with the macros
60a90ecd
MK
82.BR FD_CLR (),
83.BR FD_ISSET (),
84.BR FD_SET (),
85and
86.BR FD_ZERO ().
7ce9ffda
MK
87A newly declared set should first be cleared using
88.BR FD_ZERO ().
60a90ecd
MK
89.BR select ()
90modifies the contents of the sets according to the rules
91described below; after calling
92.BR select ()
7ce9ffda 93you can test if a file descriptor is still present in a set with the
60a90ecd
MK
94.BR FD_ISSET ()
95macro.
96.BR FD_ISSET ()
c7094399 97returns nonzero if a specified file descriptor is present in a set
7ce9ffda 98and zero if it is not.
60a90ecd 99.BR FD_CLR ()
7ce9ffda 100removes a file descriptor from a set.
61b48f93 101.SS Arguments
fea681da
MK
102.TP
103\fIreadfds\fP
104This set is watched to see if data is available for reading from any of
c13182ef 105its file descriptors.
60a90ecd
MK
106After
107.BR select ()
108has returned, \fIreadfds\fP will be
7cbaba90 109cleared of all file descriptors except for those that
7ce9ffda 110are immediately available for reading.
fea681da
MK
111.TP
112\fIwritefds\fP
113This set is watched to see if there is space to write data to any of
c13182ef 114its file descriptors.
60a90ecd
MK
115After
116.BR select ()
117has returned, \fIwritefds\fP will be
7cbaba90 118cleared of all file descriptors except for those that
7ce9ffda 119are immediately available for writing.
fea681da
MK
120.TP
121\fIexceptfds\fP
7ce9ffda
MK
122This set is watched for "exceptional conditions".
123In practice, only one such exceptional condition is common:
124the availability of \fIout-of-band\fP (OOB) data for reading
125from a TCP socket.
60a90ecd 126See
7ce9ffda
MK
127.BR recv (2),
128.BR send (2),
60a90ecd 129and
7ce9ffda
MK
130.BR tcp (7)
131for more details about OOB data.
132(One other less common case where
133.BR select (2)
b218b023 134indicates an exceptional condition occurs with pseudoterminals
7ce9ffda 135in packet mode; see
a9168840 136.BR ioctl_tty (2).)
60a90ecd
MK
137After
138.BR select ()
139has returned,
fea681da 140\fIexceptfds\fP will be cleared of all file descriptors except for those
7ce9ffda 141for which an exceptional condition has occurred.
fea681da
MK
142.TP
143\fInfds\fP
144This is an integer one more than the maximum of any file descriptor in
c13182ef 145any of the sets.