]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man4/tty.4
disk(9): Fix a few mandoc related errors
[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 November 27, 2019
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 telnet 1
58 for example).
59 Even in these cases the details of how the terminal
60 file was opened and set up is already handled by special software
61 in the system.
62 Thus, users do not normally need to worry about the details of
63 how these lines are opened or used.
64 Also, these lines are often used
65 for dialing out of a system (through an out-calling modem), but again
66 the system provides programs that hide the details of accessing
67 these terminal special files (see
68 .Xr tip 1 ) .
69 .Pp
70 When an interactive user logs in, the system prepares the line to
71 behave in a certain way (called a
72 .Em "line discipline" ) ,
73 the particular details of which is described in
74 .Xr stty 1
75 at the command level, and in
76 .Xr termios 4
77 at the programming level.
78 A user may be concerned with changing
79 settings associated with his particular login terminal and should refer
80 to the preceding man pages for the common cases.
81 The remainder of this man page is concerned
82 with describing details of using and controlling terminal devices
83 at a low level, such as that possibly required by a program wishing
84 to provide features similar to those provided by the system.
85 .Ss Terminal File Operations
86 All of the following operations are invoked using the
87 .Xr ioctl 2
88 system call.
89 Refer to that man page for a description of the
90 .Em request
91 and
92 .Em argp
93 parameters.
94 In addition to the ioctl
95 .Em requests
96 defined here, the specific line discipline
97 in effect will define other
98 .Em requests
99 specific to it (actually
100 .Xr termios 4
101 defines them as function calls, not ioctl
102 .Em requests . )
103 The following section lists the available ioctl requests.
104 The name of the request, a description of its purpose, and the typed
105 .Em argp
106 parameter (if any)
107 are listed.
108 For example, the first entry says
109 .Pp
110 .D1 Em "TIOCSPGRP int *tpgrp"
111 .Pp
112 and would be called on the terminal associated with
113 file descriptor zero by the following code fragment:
114 .Bd -literal
115         int pgrp;
116
117         pgrp = getpgrp();
118         ioctl(0, TIOCSPGRP, &pgrp);
119 .Ed
120 .Ss Terminal File Request Descriptions
121 .Bl -tag -width TIOCGWINSZ
122 .It Dv TIOCSETD Fa int *ldisc
123 This call is obsolete but left for compatibility.
124 Before
125 .Fx 8.0 ,
126 it would change to the new line discipline pointed to by
127 .Fa ldisc .
128 .It Dv TIOCGETD Fa int *ldisc
129 Return the current line discipline in the integer pointed to by
130 .Fa ldisc .
131 .It Dv TIOCSBRK Fa void
132 Set the terminal hardware into BREAK condition.
133 .It Dv TIOCCBRK Fa void
134 Clear the terminal hardware BREAK condition.
135 .It Dv TIOCSDTR Fa void
136 Assert data terminal ready (DTR).
137 .It Dv TIOCCDTR Fa void
138 Clear data terminal ready (DTR).
139 .It Dv TIOCGPGRP Fa int *tpgrp
140 Return the current process group with which the terminal is associated
141 in the integer pointed to by
142 .Fa tpgrp .
143 This is the underlying call that implements the
144 .Xr termios 4
145 .Fn tcgetattr
146 call.
147 .It Dv TIOCSPGRP Fa int *tpgrp
148 Associate the terminal with the process group (as an integer) pointed to by
149 .Fa tpgrp .
150 This is the underlying call that implements the
151 .Xr termios 4
152 .Fn tcsetattr
153 call.
154 .It Dv TIOCGETA Fa struct termios *term
155 Place the current value of the termios state associated with the
156 device in the termios structure pointed to by
157 .Fa term .
158 This is the underlying call that implements the
159 .Xr termios 4
160 .Fn tcgetattr
161 call.
162 .It Dv TIOCSETA Fa struct termios *term
163 Set the termios state associated with the device immediately.
164 This is the underlying call that implements the
165 .Xr termios 4
166 .Fn tcsetattr
167 call with the
168 .Dv TCSANOW
169 option.
170 .It Dv TIOCSETAW Fa struct termios *term
171 First wait for any output to complete, then set the termios state
172 associated with the device.
173 This is the underlying call that implements the
174 .Xr termios 4
175 .Fn tcsetattr
176 call with the
177 .Dv TCSADRAIN
178 option.
179 .It Dv TIOCSETAF Fa struct termios *term
180 First wait for any output to complete, clear any pending input,
181 then set the termios state associated with the device.
182 This is the underlying call that implements the
183 .Xr termios 4
184 .Fn tcsetattr
185 call with the
186 .Dv TCSAFLUSH
187 option.
188 .It Dv TIOCOUTQ Fa int *num
189 Place the current number of characters in the output queue in the
190 integer pointed to by
191 .Fa num .
192 .It Dv TIOCSTI Fa char *cp
193 Simulate typed input.
194 Pretend as if the terminal received the character pointed to by
195 .Fa cp .
196 .It Dv TIOCNOTTY Fa void
197 In the past, when a process that did not have a controlling terminal (see
198 .Em The Controlling Terminal
199 in
200 .Xr termios 4 )
201 first opened a terminal device, it acquired that terminal as its
202 controlling terminal.
203 For some programs this was a hazard as they
204 did not want a controlling terminal in the first place, and this
205 provides a mechanism to disassociate the controlling terminal from
206 the calling process.
207 It
208 .Em must
209 be called by opening the file
210 .Pa /dev/tty
211 and calling
212 .Dv TIOCNOTTY
213 on that file descriptor.
214 .Pp
215 The current system does not allocate a controlling terminal to
216 a process on an
217 .Fn open
218 call: there is a specific ioctl called
219 .Dv TIOCSCTTY
220 to make a terminal the controlling
221 terminal.
222 In addition, a program can
223 .Fn fork
224 and call the
225 .Fn setsid
226 system call which will place the process into its own session - which
227 has the effect of disassociating it from the controlling terminal.
228 This is the new and preferred method for programs to lose their controlling
229 terminal.
230 .Pp
231 However, environmental restrictions may prohibit the process from being able to
232 .Fn fork
233 and call the
234 .Fn setsid
235 system call to disassociate it from the controlling terminal.
236 In this case, it must use
237 .Dv TIOCNOTTY .
238 .It Dv TIOCSTOP Fa void
239 Stop output on the terminal (like typing ^S at the keyboard).
240 .It Dv TIOCSTART Fa void
241 Start output on the terminal (like typing ^Q at the keyboard).
242 .It Dv TIOCSCTTY Fa void
243 Make the terminal the controlling terminal for the process (the process
244 must not currently have a controlling terminal).
245 .It Dv TIOCDRAIN Fa void
246 Wait until all output is drained, or until the drain wait timeout expires.
247 .It Dv TIOCGDRAINWAIT Fa int *timeout
248 Return the current drain wait timeout in seconds.
249 .It Dv TIOCSDRAINWAIT Fa int *timeout
250 Set the drain wait timeout in seconds.
251 A value of zero disables timeouts.
252 The default drain wait timeout is controlled by the tunable
253 .Xr sysctl 8
254 OID
255 .Va kern.tty_drainwait .
256 .It Dv TIOCEXCL Fa void
257 Set exclusive use on the terminal.
258 No further opens are permitted except by root.
259 Of course, this means that programs that are run by
260 root (or setuid) will not obey the exclusive setting - which limits
261 the usefulness of this feature.
262 .It Dv TIOCNXCL Fa void
263 Clear exclusive use of the terminal.
264 Further opens are permitted.
265 .It Dv TIOCFLUSH Fa int *what
266 If the value of the int pointed to by
267 .Fa what
268 contains the
269 .Dv FREAD
270 bit as defined in
271 .In sys/file.h ,
272 then all characters in the input queue are cleared.
273 If it contains the
274 .Dv FWRITE
275 bit, then all characters in the output queue are cleared.
276 If the value of the integer is zero, then it behaves as if both the
277 .Dv FREAD
278 and
279 .Dv FWRITE
280 bits were set (i.e., clears both queues).
281 .It Dv TIOCGWINSZ Fa struct winsize *ws
282 Put the window size information associated with the terminal in the
283 .Va winsize
284 structure pointed to by
285 .Fa ws .
286 The window size structure contains the number of rows and columns (and pixels
287 if appropriate) of the devices attached to the terminal.
288 It is set by user software
289 and is the means by which most full\&-screen oriented programs determine the
290 screen size.
291 The
292 .Va winsize
293 structure is defined in
294 .In sys/ioctl.h .
295 .It Dv TIOCSWINSZ Fa struct winsize *ws
296 Set the window size associated with the terminal to be the value in
297 the
298 .Va winsize
299 structure pointed to by
300 .Fa ws
301 (see above).
302 .It Dv TIOCCONS Fa int *on
303 If
304 .Fa on
305 points to a non-zero integer, redirect kernel console output (kernel printf's)
306 to this terminal.
307 If
308 .Fa on
309 points to a zero integer, redirect kernel console output back to the normal
310 console.
311 This is usually used on workstations to redirect kernel messages
312 to a particular window.
313 .It Dv TIOCMSET Fa int *state
314 The integer pointed to by
315 .Fa state
316 contains bits that correspond to modem state.
317 Following is a list of defined variables and the modem state they represent:
318 .Pp
319 .Bl -tag -width TIOCMXCTS -compact
320 .It TIOCM_LE
321 Line Enable.
322 .It TIOCM_DTR
323 Data Terminal Ready.
324 .It TIOCM_RTS
325 Request To Send.
326 .It TIOCM_ST
327 Secondary Transmit.
328 .It TIOCM_SR
329 Secondary Receive.
330 .It TIOCM_CTS
331 Clear To Send.
332 .It TIOCM_CAR
333 Carrier Detect.
334 .It TIOCM_CD
335 Carrier Detect (synonym).
336 .It TIOCM_RNG
337 Ring Indication.
338 .It TIOCM_RI
339 Ring Indication (synonym).
340 .It TIOCM_DSR
341 Data Set Ready.
342 .El
343 .Pp
344 This call sets the terminal modem state to that represented by
345 .Fa state .
346 Not all terminals may support this.
347 .It Dv TIOCMGET Fa int *state
348 Return the current state of the terminal modem lines as represented
349 above in the integer pointed to by
350 .Fa state .
351 .It Dv TIOCMBIS Fa int *state
352 The bits in the integer pointed to by
353 .Fa state
354 represent modem state as described above, however the state is OR-ed
355 in with the current state.
356 .It Dv TIOCMBIC Fa int *state
357 The bits in the integer pointed to by
358 .Fa state
359 represent modem state as described above, however each bit which is on
360 in
361 .Fa state
362 is cleared in the terminal.
363 .El
364 .Sh IMPLEMENTATION NOTES
365 The total number of input and output bytes
366 through all terminal devices
367 are available via the
368 .Va kern.tty_nin
369 and
370 .Va kern.tty_nout
371 read-only
372 .Xr sysctl 8
373 variables.
374 .Sh SEE ALSO
375 .Xr stty 1 ,
376 .Xr ioctl 2 ,
377 .Xr ng_tty 4 ,
378 .Xr pty 4 ,
379 .Xr termios 4 ,
380 .Xr getty 8