]>
Commit | Line | Data |
---|---|---|
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 | 34 | select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO \- |
35478399 | 35 | synchronous 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 |
62 | Feature 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 |
72 | is used to efficiently monitor multiple file descriptors, |
73 | to see if any of them is, or becomes, "ready"; | |
74 | that is, to see whether I/O becomes possible, | |
d9cb0d7d | 75 | or an "exceptional condition" has occurred on any of the file descriptors. |
efeece04 | 76 | .PP |
7ce9ffda MK |
77 | Its principal arguments are three "sets" of file descriptors: |
78 | \fIreadfds\fP, \fIwritefds\fP, and \fIexceptfds\fP. | |
79 | Each set is declared as type | |
80 | .IR fd_set , | |
81 | and its contents can be manipulated with the macros | |
60a90ecd MK |
82 | .BR FD_CLR (), |
83 | .BR FD_ISSET (), | |
84 | .BR FD_SET (), | |
85 | and | |
86 | .BR FD_ZERO (). | |
7ce9ffda MK |
87 | A newly declared set should first be cleared using |
88 | .BR FD_ZERO (). | |
60a90ecd MK |
89 | .BR select () |
90 | modifies the contents of the sets according to the rules | |
91 | described below; after calling | |
92 | .BR select () | |
7ce9ffda | 93 | you can test if a file descriptor is still present in a set with the |
60a90ecd MK |
94 | .BR FD_ISSET () |
95 | macro. | |
96 | .BR FD_ISSET () | |
c7094399 | 97 | returns nonzero if a specified file descriptor is present in a set |
7ce9ffda | 98 | and zero if it is not. |
60a90ecd | 99 | .BR FD_CLR () |
7ce9ffda | 100 | removes a file descriptor from a set. |
61b48f93 | 101 | .SS Arguments |
fea681da MK |
102 | .TP |
103 | \fIreadfds\fP | |
104 | This set is watched to see if data is available for reading from any of | |
c13182ef | 105 | its file descriptors. |
60a90ecd MK |
106 | After |
107 | .BR select () | |
108 | has returned, \fIreadfds\fP will be | |
7cbaba90 | 109 | cleared of all file descriptors except for those that |
7ce9ffda | 110 | are immediately available for reading. |
fea681da MK |
111 | .TP |
112 | \fIwritefds\fP | |
113 | This set is watched to see if there is space to write data to any of | |
c13182ef | 114 | its file descriptors. |
60a90ecd MK |
115 | After |
116 | .BR select () | |
117 | has returned, \fIwritefds\fP will be | |
7cbaba90 | 118 | cleared of all file descriptors except for those that |
7ce9ffda | 119 | are immediately available for writing. |
fea681da MK |
120 | .TP |
121 | \fIexceptfds\fP | |
7ce9ffda MK |
122 | This set is watched for "exceptional conditions". |
123 | In practice, only one such exceptional condition is common: | |
124 | the availability of \fIout-of-band\fP (OOB) data for reading | |
125 | from a TCP socket. | |
60a90ecd | 126 | See |
7ce9ffda MK |
127 | .BR recv (2), |
128 | .BR send (2), | |
60a90ecd | 129 | and |
7ce9ffda MK |
130 | .BR tcp (7) |
131 | for more details about OOB data. | |
132 | (One other less common case where | |
133 | .BR select (2) | |
b218b023 | 134 | indicates an exceptional condition occurs with pseudoterminals |
7ce9ffda | 135 | in packet mode; see |
a9168840 | 136 | .BR ioctl_tty (2).) |
60a90ecd MK |
137 | After |
138 | .BR select () | |
139 | has returned, | |
fea681da | 140 | \fIexceptfds\fP will be cleared of all file descriptors except for those |
7ce9ffda | 141 | for which an exceptional condition has occurred. |
fea681da MK |
142 | .TP |
143 | \fInfds\fP | |
144 | This is an integer one more than the maximum of any file descriptor in | |
c13182ef | 145 | any of the sets. |