1 .\" Copyright (c) 1991, 1992, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)tty.4 8.3 (Berkeley) 4/19/94
40 .Nd general terminal interface
44 This section describes the interface to the terminal drivers
46 .Ss Terminal Special Files
47 Each hardware terminal port on the system usually has a terminal special device
48 file associated with it in the directory ``/dev/'' (for
49 example, ``/dev/tty03'').
51 the system on one of these hardware terminal ports, the system has already
52 opened the associated device and prepared the line for normal interactive
55 There is also a special case of a terminal file that connects not to
56 a hardware terminal port, but to another program on the other side.
57 These special terminal devices are called
59 and provide the mechanism necessary to give users the same interface to the
60 system when logging in over a network (using
65 Even in these cases the details of how the terminal
66 file was opened and set up is already handled by special software
68 Thus, users do not normally need to worry about the details of
69 how these lines are opened or used.
70 Also, these lines are often used
71 for dialing out of a system (through an out-calling modem), but again
72 the system provides programs that hide the details of accessing
73 these terminal special files (see
76 When an interactive user logs in, the system prepares the line to
77 behave in a certain way (called a
78 .Em "line discipline" ) ,
79 the particular details of which is described in
81 at the command level, and in
83 at the programming level.
84 A user may be concerned with changing
85 settings associated with his particular login terminal and should refer
86 to the preceding man pages for the common cases.
87 The remainder of this man page is concerned
88 with describing details of using and controlling terminal devices
89 at a low level, such as that possibly required by a program wishing
90 to provide features similar to those provided by the system.
92 A terminal file is used like any other file in the system in that
93 it can be opened, read, and written to using standard system
95 For each existing terminal file, there is a software processing module
98 is associated with it.
100 .Em "line discipline"
101 essentially glues the low level device driver code with the high
102 level generic interface routines (such as
106 and is responsible for implementing the semantics associated
108 When a terminal file is first opened by a program, the default
109 .Em "line discipline"
112 line discipline is associated with the file.
114 line discipline that is used in most cases and provides the semantics
115 that users normally associate with a terminal.
118 line discipline is in effect, the terminal file behaves and is
119 operated according to the rules described in
121 Please refer to that man page for a full description of the terminal
123 The operations described here
124 generally represent features common
126 .Em "line disciplines" ,
127 however some of these calls may not
128 make sense in conjunction with a line discipline other than
130 and some may not be supported by the underlying
131 hardware (or lack thereof, as in the case of ptys).
132 .Ss Terminal File Operations
133 All of the following operations are invoked using the
136 Refer to that man page for a description of the
141 In addition to the ioctl
143 defined here, the specific line discipline
144 in effect will define other
146 specific to it (actually
148 defines them as function calls, not ioctl
150 The following section lists the available ioctl requests.
151 The name of the request, a description of its purpose, and the typed
155 For example, the first entry says
157 .D1 Em "TIOCSETD int *ldisc"
159 and would be called on the terminal associated with
160 file descriptor zero by the following code fragment:
165 ioctl(0, TIOCSETD, &ldisc);
167 .Ss Terminal File Request Descriptions
168 .Bl -tag -width TIOCGWINSZ
169 .It Dv TIOCSETD Fa int *ldisc
170 Change to the new line discipline pointed to by
172 The available line disciplines are listed in
176 .Bl -tag -width NETGRAPHDISC -compact
178 Termios interactive line discipline.
180 Tablet line discipline.
182 Serial IP line discipline.
191 .It Dv TIOCGETD Fa int *ldisc
192 Return the current line discipline in the integer pointed to by
194 .It Dv TIOCSBRK Fa void
195 Set the terminal hardware into BREAK condition.
196 .It Dv TIOCCBRK Fa void
197 Clear the terminal hardware BREAK condition.
198 .It Dv TIOCSDTR Fa void
199 Assert data terminal ready (DTR).
200 .It Dv TIOCCDTR Fa void
201 Clear data terminal ready (DTR).
202 .It Dv TIOCGPGRP Fa int *tpgrp
203 Return the current process group with which the terminal is associated
204 in the integer pointed to by
206 This is the underlying call that implements the
210 .It Dv TIOCSPGRP Fa int *tpgrp
211 Associate the terminal with the process group (as an integer) pointed to by
213 This is the underlying call that implements the
217 .It Dv TIOCGETA Fa struct termios *term
218 Place the current value of the termios state associated with the
219 device in the termios structure pointed to by
221 This is the underlying call that implements the
225 .It Dv TIOCSETA Fa struct termios *term
226 Set the termios state associated with the device immediately.
227 This is the underlying call that implements the
233 .It Dv TIOCSETAW Fa struct termios *term
234 First wait for any output to complete, then set the termios state
235 associated with the device.
236 This is the underlying call that implements the
242 .It Dv TIOCSETAF Fa struct termios *term
243 First wait for any output to complete, clear any pending input,
244 then set the termios state associated with the device.
245 This is the underlying call that implements the
251 .It Dv TIOCOUTQ Fa int *num
252 Place the current number of characters in the output queue in the
253 integer pointed to by
255 .It Dv TIOCSTI Fa char *cp
256 Simulate typed input.
257 Pretend as if the terminal received the character pointed to by
259 .It Dv TIOCNOTTY Fa void
260 This call is obsolete but left for compatibility.
261 In the past, when a process that didn't have a controlling terminal (see
262 .Em The Controlling Terminal
265 first opened a terminal device, it acquired that terminal as its
266 controlling terminal.
267 For some programs this was a hazard as they
268 didn't want a controlling terminal in the first place, and this
269 provided a mechanism to disassociate the controlling terminal from
273 be called by opening the file
277 on that file descriptor.
279 The current system does not allocate a controlling terminal to
282 call: there is a specific ioctl called
284 to make a terminal the controlling
286 In addition, a program can
290 system call which will place the process into its own session - which
291 has the effect of disassociating it from the controlling terminal.
292 This is the new and preferred method for programs to lose their controlling
294 .It Dv TIOCSTOP Fa void
295 Stop output on the terminal (like typing ^S at the keyboard).
296 .It Dv TIOCSTART Fa void
297 Start output on the terminal (like typing ^Q at the keyboard).
298 .It Dv TIOCSCTTY Fa void
299 Make the terminal the controlling terminal for the process (the process
300 must not currently have a controlling terminal).
301 .It Dv TIOCDRAIN Fa void
302 Wait until all output is drained.
303 .It Dv TIOCEXCL Fa void
304 Set exclusive use on the terminal.
305 No further opens are permitted except by root.
306 Of course, this means that programs that are run by
307 root (or setuid) will not obey the exclusive setting - which limits
308 the usefulness of this feature.
309 .It Dv TIOCNXCL Fa void
310 Clear exclusive use of the terminal.
311 Further opens are permitted.
312 .It Dv TIOCFLUSH Fa int *what
313 If the value of the int pointed to by
319 then all characters in the input queue are cleared.
322 bit, then all characters in the output queue are cleared.
323 If the value of the integer is zero, then it behaves as if both the
327 bits were set (i.e., clears both queues).
328 .It Dv TIOCGWINSZ Fa struct winsize *ws
329 Put the window size information associated with the terminal in the
331 structure pointed to by
333 The window size structure contains the number of rows and columns (and pixels
334 if appropriate) of the devices attached to the terminal.
335 It is set by user software
336 and is the means by which most full\&-screen oriented programs determine the
340 structure is defined in
342 .It Dv TIOCSWINSZ Fa struct winsize *ws
343 Set the window size associated with the terminal to be the value in
346 structure pointed to by
349 .It Dv TIOCCONS Fa int *on
352 points to a non-zero integer, redirect kernel console output (kernel printf's)
356 points to a zero integer, redirect kernel console output back to the normal
358 This is usually used on workstations to redirect kernel messages
359 to a particular window.
360 .It Dv TIOCMSET Fa int *state
361 The integer pointed to by
363 contains bits that correspond to modem state.
364 Following is a list of defined variables and the modem state they represent:
366 .Bl -tag -width TIOCMXCTS -compact
382 Carrier Detect (synonym).
386 Ring Indication (synonym).
391 This call sets the terminal modem state to that represented by
393 Not all terminals may support this.
394 .It Dv TIOCMGET Fa int *state
395 Return the current state of the terminal modem lines as represented
396 above in the integer pointed to by
398 .It Dv TIOCMBIS Fa int *state
399 The bits in the integer pointed to by
401 represent modem state as described above, however the state is OR-ed
402 in with the current state.
403 .It Dv TIOCMBIC Fa int *state
404 The bits in the integer pointed to by
406 represent modem state as described above, however each bit which is on
409 is cleared in the terminal.
411 .Sh IMPLEMENTATION NOTES
412 The total number of input and output bytes
413 through all terminal devices
414 are available via the