1 .\" $NetBSD: tty.4,v 1.24 2006/10/13 20:32:05 wiz Exp $
3 .\" Copyright (c) 1991, 1992, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)tty.4 8.3 (Berkeley) 4/19/94
37 .Nd general terminal interface
41 This section describes the interface to the terminal drivers
43 .Ss Terminal Special Files
44 Each hardware terminal port on the system usually has two terminal special
45 device files associated with it in the directory
54 special file is used for dial-in modems and terminals.
56 the system on one of these hardware terminal ports, the system has already
57 opened the associated device and prepared the line for normal interactive
63 special file is a SunOS-compatible dial-out device. Unlike
64 the dial-in device, opening the dial-out device never blocks. If the
65 corresponding dial-in device is already opened (not blocked in the open waiting
66 for carrier), then the dial-out open will fail immediately; otherwise it will
67 succeed immediately. While the dial-out device is open, the dial-in device may
68 not be opened. If the dial-in open is blocking, it will wait until the dial-out
69 device is closed (and carrier is detected); otherwise it will fail immediately.
71 There is also a special case of a terminal file that connects not to
72 a hardware terminal port, but to another program on the other side.
73 These special terminal devices are called
76 and provide the mechanism necessary to give users the same interface to the
77 system when logging in over a network (using
81 for example.) Even in these cases the details of how the terminal
82 file was opened and set up is already handled by special software
84 Thus, users do not normally need to worry about the details of
85 how these lines are opened or used. Also, these lines are often used
86 for dialing out of a system (through an out-calling modem), but again
87 the system provides programs that hide the details of accessing
88 these terminal special files (see
91 When an interactive user logs in, the system prepares the line to
92 behave in a certain way (called a
93 .Em line discipline ) ,
94 the particular details of which is described in
96 at the command level, and in
98 at the programming level. A user may be concerned with changing
99 settings associated with his particular login terminal and should refer
100 to the preceding man pages for the common cases. The remainder of
101 this man page is concerned
102 with describing details of using and controlling terminal devices
103 at a low level, such as that possibly required by a program wishing
104 to provide features similar to those provided by the system.
106 A terminal file is used like any other file in the system in that
107 it can be opened, read, and written to using standard system
108 calls. For each existing terminal file, there is a software processing module
111 associated with it. The
113 essentially glues the low level device driver code with the high
114 level generic interface routines (such as
118 and is responsible for implementing the semantics associated
119 with the device. When a terminal file is first opened by a program,
124 line discipline is associated with the file. This is the primary
125 line discipline that is used in most cases and provides the semantics
126 that users normally associate with a terminal. When the
128 line discipline is in effect, the terminal file behaves and is
129 operated according to the rules described in
131 Please refer to that man page for a full description of the terminal
133 The operations described here
134 generally represent features common
136 .Em line disciplines ,
137 however some of these calls may not
138 make sense in conjunction with a line discipline other than
140 and some may not be supported by the underlying
141 hardware (or lack thereof, as in the case of ptys).
142 .Ss Terminal File Operations
143 All of the following operations are invoked using the
145 system call. Refer to that man page for a description of
151 In addition to the ioctl
153 defined here, the specific line discipline
154 in effect will define other
156 specific to it (actually
158 defines them as function calls, not ioctl
160 The following section lists the available ioctl requests. The
161 name of the request, a description of its purpose, and the typed
164 are listed. For example, the first entry says
166 .D1 Em TIOCSLINED char name[32]
168 and would be called on the terminal associated with
169 file descriptor zero by the following code fragment:
171 ioctl(0, TIOCSLINED, "termios");
173 .Ss Terminal File Request Descriptions
174 .Bl -tag -width TIOCGWINSZ
175 .It Dv TIOCSLINED Fa char name[32]
176 Change to the new line discipline called
179 .It Dv TIOCGLINED Fa char name[32]
180 Return the current line discipline in the string pointed to by
182 .It Dv TIOCSBRK Fa void
183 Set the terminal hardware into BREAK condition.
184 .It Dv TIOCCBRK Fa void
185 Clear the terminal hardware BREAK condition.
186 .It Dv TIOCSDTR Fa void
187 Assert data terminal ready (DTR).
188 .It Dv TIOCCDTR Fa void
189 Clear data terminal ready (DTR).
190 .It Dv TIOCGPGRP Fa int *tpgrp
191 Return the current process group the terminal is associated
192 with in the integer pointed to by
194 This is the underlying call that implements the
197 .It Dv TIOCSPGRP Fa int *tpgrp
198 Associate the terminal with the process group (as an integer) pointed to by
200 This is the underlying call that implements the
203 .It Dv TIOCGETA Fa struct termios *term
204 Place the current value of the termios state associated with the
205 device in the termios structure pointed to by
207 This is the underlying call that implements the
210 .It Dv TIOCSETA Fa struct termios *term
211 Set the termios state associated with the device immediately.
212 This is the underlying call that implements the
217 .It Dv TIOCSETAW Fa struct termios *term
218 First wait for any output to complete, then set the termios state
219 associated with the device.
220 This is the underlying call that implements the
225 .It Dv TIOCSETAF Fa struct termios *term
226 First wait for any output to complete, clear any pending input,
227 then set the termios state associated with the device.
228 This is the underlying call that implements the
233 .It Dv TIOCOUTQ Fa int *num
234 Place the current number of characters in the output queue in the
235 integer pointed to by
237 .It Dv TIOCSTI Fa char *cp
238 Simulate typed input. Pretend as if the terminal received the
239 character pointed to by
241 .It Dv TIOCNOTTY Fa void
242 This call is obsolete but left for compatibility. In the past, when
243 a process that didn't have a controlling terminal (see
244 .Em The Controlling Terminal
247 first opened a terminal device, it acquired that terminal as its
248 controlling terminal. For some programs this was a hazard as they
249 didn't want a controlling terminal in the first place, and this
250 provided a mechanism to disassociate the controlling terminal from
251 the calling process. It
253 be called by opening the file
257 on that file descriptor.
259 The current system does not allocate a controlling terminal to
262 call: there is a specific ioctl called
264 to make a terminal the controlling
266 In addition, a program can
270 system call which will place the process into its own session - which
271 has the effect of disassociating it from the controlling terminal. This
272 is the new and preferred method for programs to lose their controlling
274 .It Dv TIOCSTOP Fa void
275 Stop output on the terminal (like typing ^S at the keyboard).
276 .It Dv TIOCSTART Fa void
277 Start output on the terminal (like typing ^Q at the keyboard).
278 .It Dv TIOCSCTTY Fa void
279 Make the terminal the controlling terminal for the process (the process
280 must not currently have a controlling terminal).
281 .It Dv TIOCDRAIN Fa void
282 Wait until all output is drained.
283 .It Dv TIOCEXCL Fa void
284 Set exclusive use on the terminal. No further opens are permitted
285 except by root. Of course, this means that programs that are run by
286 root (or setuid) will not obey the exclusive setting - which limits
287 the usefulness of this feature.
288 .It Dv TIOCNXCL Fa void
289 Clear exclusive use of the terminal. Further opens are permitted.
290 .It Dv TIOCFLUSH Fa int *what
291 If the value of the int pointed to by
297 then all characters in the input queue are cleared. If it contains
300 bit, then all characters in the output queue are cleared. If the
301 value of the integer is zero, then it behaves as if both the
305 bits were set (i.e. clears both queues).
306 .It Dv TIOCGWINSZ Fa struct winsize *ws
307 Put the window size information associated with the terminal in the
309 structure pointed to by
311 The window size structure contains the number of rows and columns (and pixels
312 if appropriate) of the devices attached to the terminal. It is set by user software
313 and is the means by which most full\&-screen oriented programs determine the
316 structure is defined in
318 .It Dv TIOCSWINSZ Fa struct winsize *ws
319 Set the window size associated with the terminal to be the value in
322 structure pointed to by
325 .It Dv TIOCCONS Fa int *on
328 points to a non-zero integer, redirect kernel console output (kernel printf's)
332 points to a zero integer, redirect kernel console output back to the normal
333 console. This is usually used on workstations to redirect kernel messages
334 to a particular window.
335 .It Dv TIOCMSET Fa int *state
336 The integer pointed to by
338 contains bits that correspond to modem state.
339 Following is a list of defined variables and the modem state they represent:
341 .Bl -tag -width TIOCMXCTS -compact
357 Carrier Detect (synonym).
361 Ring Indication (synonym).
366 This call sets the terminal modem state to that represented by
368 Not all terminals may support this.
369 .It Dv TIOCMGET Fa int *state
370 Return the current state of the terminal modem lines as represented
371 above in the integer pointed to by
373 .It Dv TIOCMBIS Fa int *state
374 The bits in the integer pointed to by
376 represent modem state as described above, however the state is OR-ed
377 in with the current state.
378 .It Dv TIOCMBIC Fa int *state
379 The bits in the integer pointed to by
381 represent modem state as described above, however each bit which is on
384 is cleared in the terminal.
385 .It Dv TIOCSFLAGS Fa int *state
386 The bits in the integer pointed to by
388 contain bits that correspond to serial port state.
389 Following is a list of defined flag values and the serial port state they
392 .Bl -tag -width TIOCFLAG_SOFTCAR -compact
394 Ignore hardware carrier.
412 This call sets the serial port state to that represented by
414 Not all serial ports may support this.
415 .It Dv TIOCGFLAGS Fa int *state
416 Return the current state of the serial port as represented
417 above in the integer pointed to by
421 Two ioctls are maintained for backwards compatibility. They provide
422 methods to get and set the current line discipline, but are not
424 .Bl -tag -width TIOCGWINSZ
425 .It Dv TIOCSETD Fa int *ldisc
426 Change to the new line discipline pointed to by
428 The old list of available line disciplines are listed in
432 .Bl -tag -width TIOCGWINSZ -compact
434 Termios interactive line discipline.
436 Tablet line discipline.
438 Serial IP line discipline.
440 Point to Point Protocol line discipline.
442 Starmode Radio IP line discipline.
445 .It Dv TIOCGETD Fa int *ldisc
446 Return the current line discipline in the integer pointed to by
461 Separate dial-out device files were implemented in SunOS 4. They were cloned
462 by Charles M. Hannum for