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.
91 .Ss Terminal File Operations
92 All of the following operations are invoked using the
95 Refer to that man page for a description of the
100 In addition to the ioctl
102 defined here, the specific line discipline
103 in effect will define other
105 specific to it (actually
107 defines them as function calls, not ioctl
109 The following section lists the available ioctl requests.
110 The name of the request, a description of its purpose, and the typed
114 For example, the first entry says
116 .D1 Em "TIOCSPGRP int *tpgrp"
118 and would be called on the terminal associated with
119 file descriptor zero by the following code fragment:
124 ioctl(0, TIOCSPGRP, &pgrp);
126 .Ss Terminal File Request Descriptions
127 .Bl -tag -width TIOCGWINSZ
128 .It Dv TIOCSETD Fa int *ldisc
129 This call is obsolete but left for compatibility.
132 it would change to the new line discipline pointed to by
135 .It Dv TIOCGETD Fa int *ldisc
136 Return the current line discipline in the integer pointed to by
138 .It Dv TIOCSBRK Fa void
139 Set the terminal hardware into BREAK condition.
140 .It Dv TIOCCBRK Fa void
141 Clear the terminal hardware BREAK condition.
142 .It Dv TIOCSDTR Fa void
143 Assert data terminal ready (DTR).
144 .It Dv TIOCCDTR Fa void
145 Clear data terminal ready (DTR).
146 .It Dv TIOCGPGRP Fa int *tpgrp
147 Return the current process group with which the terminal is associated
148 in the integer pointed to by
150 This is the underlying call that implements the
154 .It Dv TIOCSPGRP Fa int *tpgrp
155 Associate the terminal with the process group (as an integer) pointed to by
157 This is the underlying call that implements the
161 .It Dv TIOCGETA Fa struct termios *term
162 Place the current value of the termios state associated with the
163 device in the termios structure pointed to by
165 This is the underlying call that implements the
169 .It Dv TIOCSETA Fa struct termios *term
170 Set the termios state associated with the device immediately.
171 This is the underlying call that implements the
177 .It Dv TIOCSETAW Fa struct termios *term
178 First wait for any output to complete, then set the termios state
179 associated with the device.
180 This is the underlying call that implements the
186 .It Dv TIOCSETAF Fa struct termios *term
187 First wait for any output to complete, clear any pending input,
188 then set the termios state associated with the device.
189 This is the underlying call that implements the
195 .It Dv TIOCOUTQ Fa int *num
196 Place the current number of characters in the output queue in the
197 integer pointed to by
199 .It Dv TIOCSTI Fa char *cp
200 Simulate typed input.
201 Pretend as if the terminal received the character pointed to by
203 .It Dv TIOCNOTTY Fa void
204 This call is obsolete but left for compatibility.
205 In the past, when a process that did not have a controlling terminal (see
206 .Em The Controlling Terminal
209 first opened a terminal device, it acquired that terminal as its
210 controlling terminal.
211 For some programs this was a hazard as they
212 did not want a controlling terminal in the first place, and this
213 provided a mechanism to disassociate the controlling terminal from
217 be called by opening the file
221 on that file descriptor.
223 The current system does not allocate a controlling terminal to
226 call: there is a specific ioctl called
228 to make a terminal the controlling
230 In addition, a program can
234 system call which will place the process into its own session - which
235 has the effect of disassociating it from the controlling terminal.
236 This is the new and preferred method for programs to lose their controlling
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.
247 .It Dv TIOCEXCL Fa void
248 Set exclusive use on the terminal.
249 No further opens are permitted except by root.
250 Of course, this means that programs that are run by
251 root (or setuid) will not obey the exclusive setting - which limits
252 the usefulness of this feature.
253 .It Dv TIOCNXCL Fa void
254 Clear exclusive use of the terminal.
255 Further opens are permitted.
256 .It Dv TIOCFLUSH Fa int *what
257 If the value of the int pointed to by
263 then all characters in the input queue are cleared.
266 bit, then all characters in the output queue are cleared.
267 If the value of the integer is zero, then it behaves as if both the
271 bits were set (i.e., clears both queues).
272 .It Dv TIOCGWINSZ Fa struct winsize *ws
273 Put the window size information associated with the terminal in the
275 structure pointed to by
277 The window size structure contains the number of rows and columns (and pixels
278 if appropriate) of the devices attached to the terminal.
279 It is set by user software
280 and is the means by which most full\&-screen oriented programs determine the
284 structure is defined in
286 .It Dv TIOCSWINSZ Fa struct winsize *ws
287 Set the window size associated with the terminal to be the value in
290 structure pointed to by
293 .It Dv TIOCCONS Fa int *on
296 points to a non-zero integer, redirect kernel console output (kernel printf's)
300 points to a zero integer, redirect kernel console output back to the normal
302 This is usually used on workstations to redirect kernel messages
303 to a particular window.
304 .It Dv TIOCMSET Fa int *state
305 The integer pointed to by
307 contains bits that correspond to modem state.
308 Following is a list of defined variables and the modem state they represent:
310 .Bl -tag -width TIOCMXCTS -compact
326 Carrier Detect (synonym).
330 Ring Indication (synonym).
335 This call sets the terminal modem state to that represented by
337 Not all terminals may support this.
338 .It Dv TIOCMGET Fa int *state
339 Return the current state of the terminal modem lines as represented
340 above in the integer pointed to by
342 .It Dv TIOCMBIS Fa int *state
343 The bits in the integer pointed to by
345 represent modem state as described above, however the state is OR-ed
346 in with the current state.
347 .It Dv TIOCMBIC Fa int *state
348 The bits in the integer pointed to by
350 represent modem state as described above, however each bit which is on
353 is cleared in the terminal.
355 .Sh IMPLEMENTATION NOTES
356 The total number of input and output bytes
357 through all terminal devices
358 are available via the