]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man4/tty.4
Update compiler-rt to release_39 branch r288513. Since this contains a
[FreeBSD/FreeBSD.git] / share / man / man4 / tty.4
1 .\" Copyright (c) 1991, 1992, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)tty.4       8.3 (Berkeley) 4/19/94
29 .\" $FreeBSD$
30 .\"
31 .Dd December 26, 2009
32 .Dt TTY 4
33 .Os
34 .Sh NAME
35 .Nm tty
36 .Nd general terminal interface
37 .Sh SYNOPSIS
38 .In sys/ioctl.h
39 .Sh DESCRIPTION
40 This section describes the interface to the terminal drivers
41 in the system.
42 .Ss Terminal Special Files
43 Each hardware terminal port on the system usually has a terminal special device
44 file associated with it in the directory ``/dev/'' (for
45 example, ``/dev/tty03'').
46 When a user logs into
47 the system on one of these hardware terminal ports, the system has already
48 opened the associated device and prepared the line for normal interactive
49 use (see
50 .Xr getty 8 . )
51 There is also a special case of a terminal file that connects not to
52 a hardware terminal port, but to another program on the other side.
53 These special terminal devices are called
54 .Em ptys
55 and provide the mechanism necessary to give users the same interface to the
56 system when logging in over a network (using
57 .Xr rlogin 1 ,
58 or
59 .Xr telnet 1
60 for example).
61 Even in these cases the details of how the terminal
62 file was opened and set up is already handled by special software
63 in the system.
64 Thus, users do not normally need to worry about the details of
65 how these lines are opened or used.
66 Also, these lines are often used
67 for dialing out of a system (through an out-calling modem), but again
68 the system provides programs that hide the details of accessing
69 these terminal special files (see
70 .Xr tip 1 ) .
71 .Pp
72 When an interactive user logs in, the system prepares the line to
73 behave in a certain way (called a
74 .Em "line discipline" ) ,
75 the particular details of which is described in
76 .Xr stty 1
77 at the command level, and in
78 .Xr termios 4
79 at the programming level.
80 A user may be concerned with changing
81 settings associated with his particular login terminal and should refer
82 to the preceding man pages for the common cases.
83 The remainder of this man page is concerned
84 with describing details of using and controlling terminal devices
85 at a low level, such as that possibly required by a program wishing
86 to provide features similar to those provided by the system.
87 .Ss Terminal File Operations
88 All of the following operations are invoked using the
89 .Xr ioctl 2
90 system call.
91 Refer to that man page for a description of the
92 .Em request
93 and
94 .Em argp
95 parameters.
96 In addition to the ioctl
97 .Em requests
98 defined here, the specific line discipline
99 in effect will define other
100 .Em requests
101 specific to it (actually
102 .Xr termios 4
103 defines them as function calls, not ioctl
104 .Em requests . )
105 The following section lists the available ioctl requests.
106 The name of the request, a description of its purpose, and the typed
107 .Em argp
108 parameter (if any)
109 are listed.
110 For example, the first entry says
111 .Pp
112 .D1 Em "TIOCSPGRP int *tpgrp"
113 .Pp
114 and would be called on the terminal associated with
115 file descriptor zero by the following code fragment:
116 .Bd -literal
117         int pgrp;
118
119         pgrp = getpgrp();
120         ioctl(0, TIOCSPGRP, &pgrp);
121 .Ed
122 .Ss Terminal File Request Descriptions
123 .Bl -tag -width TIOCGWINSZ
124 .It Dv TIOCSETD Fa int *ldisc
125 This call is obsolete but left for compatibility.
126 Before
127 .Fx 8.0 ,
128 it would change to the new line discipline pointed to by
129 .Fa ldisc .
130 .It Dv TIOCGETD Fa int *ldisc
131 Return the current line discipline in the integer pointed to by
132 .Fa ldisc .
133 .It Dv TIOCSBRK Fa void
134 Set the terminal hardware into BREAK condition.
135 .It Dv TIOCCBRK Fa void
136 Clear the terminal hardware BREAK condition.
137 .It Dv TIOCSDTR Fa void
138 Assert data terminal ready (DTR).
139 .It Dv TIOCCDTR Fa void
140 Clear data terminal ready (DTR).
141 .It Dv TIOCGPGRP Fa int *tpgrp
142 Return the current process group with which the terminal is associated
143 in the integer pointed to by
144 .Fa tpgrp .
145 This is the underlying call that implements the
146 .Xr termios 4
147 .Fn tcgetattr
148 call.
149 .It Dv TIOCSPGRP Fa int *tpgrp
150 Associate the terminal with the process group (as an integer) pointed to by
151 .Fa tpgrp .
152 This is the underlying call that implements the
153 .Xr termios 4
154 .Fn tcsetattr
155 call.
156 .It Dv TIOCGETA Fa struct termios *term
157 Place the current value of the termios state associated with the
158 device in the termios structure pointed to by
159 .Fa term .
160 This is the underlying call that implements the
161 .Xr termios 4
162 .Fn tcgetattr
163 call.
164 .It Dv TIOCSETA Fa struct termios *term
165 Set the termios state associated with the device immediately.
166 This is the underlying call that implements the
167 .Xr termios 4
168 .Fn tcsetattr
169 call with the
170 .Dv TCSANOW
171 option.
172 .It Dv TIOCSETAW Fa struct termios *term
173 First wait for any output to complete, then set the termios state
174 associated with the device.
175 This is the underlying call that implements the
176 .Xr termios 4
177 .Fn tcsetattr
178 call with the
179 .Dv TCSADRAIN
180 option.
181 .It Dv TIOCSETAF Fa struct termios *term
182 First wait for any output to complete, clear any pending input,
183 then set the termios state associated with the device.
184 This is the underlying call that implements the
185 .Xr termios 4
186 .Fn tcsetattr
187 call with the
188 .Dv TCSAFLUSH
189 option.
190 .It Dv TIOCOUTQ Fa int *num
191 Place the current number of characters in the output queue in the
192 integer pointed to by
193 .Fa num .
194 .It Dv TIOCSTI Fa char *cp
195 Simulate typed input.
196 Pretend as if the terminal received the character pointed to by
197 .Fa cp .
198 .It Dv TIOCNOTTY Fa void
199 This call is obsolete but left for compatibility.
200 In the past, when a process that did not have a controlling terminal (see
201 .Em The Controlling Terminal
202 in
203 .Xr termios 4 )
204 first opened a terminal device, it acquired that terminal as its
205 controlling terminal.
206 For some programs this was a hazard as they
207 did not want a controlling terminal in the first place, and this
208 provided a mechanism to disassociate the controlling terminal from
209 the calling process.
210 It
211 .Em must
212 be called by opening the file
213 .Pa /dev/tty
214 and calling
215 .Dv TIOCNOTTY
216 on that file descriptor.
217 .Pp
218 The current system does not allocate a controlling terminal to
219 a process on an
220 .Fn open
221 call: there is a specific ioctl called
222 .Dv TIOCSCTTY
223 to make a terminal the controlling
224 terminal.
225 In addition, a program can
226 .Fn fork
227 and call the
228 .Fn setsid
229 system call which will place the process into its own session - which
230 has the effect of disassociating it from the controlling terminal.
231 This is the new and preferred method for programs to lose their controlling
232 terminal.
233 .It Dv TIOCSTOP Fa void
234 Stop output on the terminal (like typing ^S at the keyboard).
235 .It Dv TIOCSTART Fa void
236 Start output on the terminal (like typing ^Q at the keyboard).
237 .It Dv TIOCSCTTY Fa void
238 Make the terminal the controlling terminal for the process (the process
239 must not currently have a controlling terminal).
240 .It Dv TIOCDRAIN Fa void
241 Wait until all output is drained.
242 .It Dv TIOCEXCL Fa void
243 Set exclusive use on the terminal.
244 No further opens are permitted except by root.
245 Of course, this means that programs that are run by
246 root (or setuid) will not obey the exclusive setting - which limits
247 the usefulness of this feature.
248 .It Dv TIOCNXCL Fa void
249 Clear exclusive use of the terminal.
250 Further opens are permitted.
251 .It Dv TIOCFLUSH Fa int *what
252 If the value of the int pointed to by
253 .Fa what
254 contains the
255 .Dv FREAD
256 bit as defined in
257 .In sys/file.h ,
258 then all characters in the input queue are cleared.
259 If it contains the
260 .Dv FWRITE
261 bit, then all characters in the output queue are cleared.
262 If the value of the integer is zero, then it behaves as if both the
263 .Dv FREAD
264 and
265 .Dv FWRITE
266 bits were set (i.e., clears both queues).
267 .It Dv TIOCGWINSZ Fa struct winsize *ws
268 Put the window size information associated with the terminal in the
269 .Va winsize
270 structure pointed to by
271 .Fa ws .
272 The window size structure contains the number of rows and columns (and pixels
273 if appropriate) of the devices attached to the terminal.
274 It is set by user software
275 and is the means by which most full\&-screen oriented programs determine the
276 screen size.
277 The
278 .Va winsize
279 structure is defined in
280 .In sys/ioctl.h .
281 .It Dv TIOCSWINSZ Fa struct winsize *ws
282 Set the window size associated with the terminal to be the value in
283 the
284 .Va winsize
285 structure pointed to by
286 .Fa ws
287 (see above).
288 .It Dv TIOCCONS Fa int *on
289 If
290 .Fa on
291 points to a non-zero integer, redirect kernel console output (kernel printf's)
292 to this terminal.
293 If
294 .Fa on
295 points to a zero integer, redirect kernel console output back to the normal
296 console.
297 This is usually used on workstations to redirect kernel messages
298 to a particular window.
299 .It Dv TIOCMSET Fa int *state
300 The integer pointed to by
301 .Fa state
302 contains bits that correspond to modem state.
303 Following is a list of defined variables and the modem state they represent:
304 .Pp
305 .Bl -tag -width TIOCMXCTS -compact
306 .It TIOCM_LE
307 Line Enable.
308 .It TIOCM_DTR
309 Data Terminal Ready.
310 .It TIOCM_RTS
311 Request To Send.
312 .It TIOCM_ST
313 Secondary Transmit.
314 .It TIOCM_SR
315 Secondary Receive.
316 .It TIOCM_CTS
317 Clear To Send.
318 .It TIOCM_CAR
319 Carrier Detect.
320 .It TIOCM_CD
321 Carrier Detect (synonym).
322 .It TIOCM_RNG
323 Ring Indication.
324 .It TIOCM_RI
325 Ring Indication (synonym).
326 .It TIOCM_DSR
327 Data Set Ready.
328 .El
329 .Pp
330 This call sets the terminal modem state to that represented by
331 .Fa state .
332 Not all terminals may support this.
333 .It Dv TIOCMGET Fa int *state
334 Return the current state of the terminal modem lines as represented
335 above in the integer pointed to by
336 .Fa state .
337 .It Dv TIOCMBIS Fa int *state
338 The bits in the integer pointed to by
339 .Fa state
340 represent modem state as described above, however the state is OR-ed
341 in with the current state.
342 .It Dv TIOCMBIC Fa int *state
343 The bits in the integer pointed to by
344 .Fa state
345 represent modem state as described above, however each bit which is on
346 in
347 .Fa state
348 is cleared in the terminal.
349 .El
350 .Sh IMPLEMENTATION NOTES
351 The total number of input and output bytes
352 through all terminal devices
353 are available via the
354 .Va kern.tk_nin
355 and
356 .Va kern.tk_nout
357 read-only
358 .Xr sysctl 8
359 variables.
360 .Sh SEE ALSO
361 .Xr stty 1 ,
362 .Xr ioctl 2 ,
363 .Xr ng_tty 4 ,
364 .Xr pty 4 ,
365 .Xr termios 4 ,
366 .Xr getty 8