1TTY(4) Kernel Interfaces Manual TTY(4)
2
3
4
6 tty - general terminal interface
7
9 This section describes both a particular special file, and the general
10 nature of the terminal interface.
11
12 The file /dev/tty is, in each process, a synonym for the control termi‐
13 nal associated with that process. It is useful for programs that wish
14 to be sure of writing messages on the terminal no matter how output has
15 been redirected. It can also be used for programs that demand a file
16 name for output, when typed output is desired and it is tiresome to
17 find out which terminal is currently in use.
18
19 As for terminals in general: all of the low-speed asynchronous communi‐
20 cations ports use the same general interface, no matter what hardware
21 is involved. The remainder of this section discusses the common fea‐
22 tures of the interface.
23
24 When a terminal file is opened, it causes the process to wait until a
25 connection is established. In practice user's programs seldom open
26 these files; they are opened by init and become a user's input and out‐
27 put file. The very first terminal file open in a process becomes the
28 control terminal for that process. The control terminal plays a spe‐
29 cial role in handling quit or interrupt signals, as discussed below.
30 The control terminal is inherited by a child process during a fork,
31 even if the control terminal is closed. The set of processes that thus
32 share a control terminal is called a process group; all members of a
33 process group receive certain signals together, see DEL below and
34 kill(2).
35
36 A terminal associated with one of these files ordinarily operates in
37 full-duplex mode. Characters may be typed at any time, even while out‐
38 put is occurring, and are only lost when the system's character input
39 buffers become completely choked, which is rare, or when the user has
40 accumulated the maximum allowed number of input characters that have
41 not yet been read by some program. Currently this limit is 256 charac‐
42 ters. When the input limit is reached all the saved characters are
43 thrown away without notice.
44
45 Normally, terminal input is processed in units of lines. This means
46 that a program attempting to read will be suspended until an entire
47 line has been typed. Also, no matter how many characters are requested
48 in the read call, at most one line will be returned. It is not however
49 necessary to read a whole line at once; any number of characters may be
50 requested in a read, even one, without losing information. There are
51 special modes, discussed below, that permit the program to read each
52 character as typed without waiting for a full line.
53
54 During input, erase and kill processing is normally done. By default,
55 the character `#' erases the last character typed, except that it will
56 not erase beyond the beginning of a line or an EOT. By default, the
57 character `@' kills the entire line up to the point where it was typed,
58 but not beyond an EOT. Both these characters operate on a keystroke
59 basis independently of any backspacing or tabbing that may have been
60 done. Either `@' or `#' may be entered literally by preceding it by
61 `\'; the erase or kill character remains, but the `\' disappears.
62 These two characters may be changed to others.
63
64 When desired, all upper-case letters are mapped into the corresponding
65 lower-case letter. The upper-case letter may be generated by preceding
66 it by `\'. In addition, the following escape sequences can be gener‐
67 ated on output and accepted on input:
68
69 for use
70 ` \´
71 | \!
72 ~ \^
73 { \(
74 } \)
75
76 Certain ASCII control characters have special meaning. These charac‐
77 ters are not passed to a reading program except in raw mode where they
78 lose their special character. Also, it is possible to change these
79 characters from the default; see below.
80
81 EOT (Control-D) may be used to generate an end of file from a termi‐
82 nal. When an EOT is received, all the characters waiting to be
83 read are immediately passed to the program, without waiting for
84 a new-line, and the EOT is discarded. Thus if there are no
85 characters waiting, which is to say the EOT occurred at the
86 beginning of a line, zero characters will be passed back, and
87 this is the standard end-of-file indication.
88
89 DEL (Rubout) is not passed to a program but generates an interrupt
90 signal which is sent to all processes with the associated con‐
91 trol terminal. Normally each such process is forced to termi‐
92 nate, but arrangements may be made either to ignore the signal
93 or to receive a trap to an agreed-upon location. See signal(2).
94
95 FS (Control-\ or control-shift-L) generates the quit signal. Its
96 treatment is identical to the interrupt signal except that
97 unless a receiving process has made other arrangements it will
98 not only be terminated but a core image file will be generated.
99
100 DC3 (Control-S) delays all printing on the terminal until something
101 is typed in.
102
103 DC1 (Control-Q) restarts printing after DC3 without generating any
104 input to a program.
105
106 When the carrier signal from the dataset drops (usually because the
107 user has hung up his terminal) a hangup signal is sent to all processes
108 with the terminal as control terminal. Unless other arrangements have
109 been made, this signal causes the processes to terminate. If the
110 hangup signal is ignored, any read returns with an end-of-file indica‐
111 tion. Thus programs that read a terminal and test for end-of-file on
112 their input can terminate appropriately when hung up on.
113
114 When one or more characters are written, they are actually transmitted
115 to the terminal as soon as previously-written characters have finished
116 typing. Input characters are echoed by putting them in the output
117 queue as they arrive. When a process produces characters more rapidly
118 than they can be typed, it will be suspended when its output queue
119 exceeds some limit. When the queue has drained down to some threshold
120 the program is resumed. Even parity is always generated on output.
121 The EOT character is not transmitted (except in raw mode) to prevent
122 terminals that respond to it from hanging up.
123
124 Several ioctl(2) calls apply to terminals. Most of them use the fol‐
125 lowing structure, defined in <sgtty.h>:
126
127 struct sgttyb {
128 char sg_ispeed;
129 char sg_ospeed;
130 char sg_erase;
131 char sg_kill;
132 int sg_flags;
133 };
134
135 The sg_ispeed and sg_ospeed fields describe the input and output speeds
136 of the device according to the following table, which corresponds to
137 the DEC DH-11 interface. If other hardware is used, impossible speed
138 changes are ignored. Symbolic values in the table are as defined in
139 <sgtty.h>.
140
141 B0 0 (hang up dataphone)
142 B50 1 50 baud
143 B75 2 75 baud
144 B110 3 110 baud
145 B134 4 134.5 baud
146 B150 5 150 baud
147 B200 6 200 baud
148 B300 7 300 baud
149 B600 8 600 baud
150 B1200 9 1200 baud
151 B1800 10 1800 baud
152 B2400 11 2400 baud
153 B4800 12 4800 baud
154 B9600 13 9600 baud
155 EXTA 14 External A
156 EXTB 15 External B
157
158 In the current configuration, only 110, 150, 300 and 1200 baud are
159 really supported on dial-up lines. Code conversion and line control
160 required for IBM 2741's (134.5 baud) must be implemented by the user's
161 program. The half-duplex line discipline required for the 202 dataset
162 (1200 baud) is not supplied; full-duplex 212 datasets work fine.
163
164 The sg_erase and sg_kill fields of the argument structure specify the
165 erase and kill characters respectively. (Defaults are # and @.)
166
167 The sg_flags field of the argument structure contains several bits that
168 determine the system's treatment of the terminal:
169
170 ALLDELAY 0177400 Delay algorithm selection
171 BSDELAY 0100000 Select backspace delays (not implemented):
172 BS0 0
173 BS1 0100000
174 VTDELAY 0040000 Select form-feed and vertical-tab delays:
175 FF0 0
176 FF1 0100000
177 CRDELAY 0030000 Select carriage-return delays:
178 CR0 0
179 CR1 0010000
180 CR2 0020000
181 CR3 0030000
182 TBDELAY 0006000 Select tab delays:
183 TAB0 0
184 TAB1 0001000
185 TAB2 0004000
186 XTABS 0006000
187 NLDELAY 0001400 Select new-line delays:
188 NL0 0
189 NL1 0000400
190 NL2 0001000
191 NL3 0001400
192 EVENP 0000200 Even parity allowed on input (most terminals)
193 ODDP 0000100 Odd parity allowed on input
194 RAW 0000040 Raw mode: wake up on all characters, 8-bit interface
195 CRMOD 0000020 Map CR into LF; echo LF or CR as CR-LF
196 ECHO 0000010 Echo (full duplex)
197 LCASE 0000004 Map upper case to lower on input
198 CBREAK 0000002 Return each character as soon as typed
199 TANDEM 0000001 Automatic flow control
200
201 The delay bits specify how long transmission stops to allow for mechan‐
202 ical or other movement when certain characters are sent to the termi‐
203 nal. In all cases a value of 0 indicates no delay.
204
205 Backspace delays are currently ignored but might be used for Terminet
206 300's.
207
208 If a form-feed/vertical tab delay is specified, it lasts for about 2
209 seconds.
210
211 Carriage-return delay type 1 lasts about .08 seconds and is suitable
212 for the Terminet 300. Delay type 2 lasts about .16 seconds and is
213 suitable for the VT05 and the TI 700. Delay type 3 is unimplemented
214 and is 0.
215
216 New-line delay type 1 is dependent on the current column and is tuned
217 for Teletype model 37's. Type 2 is useful for the VT05 and is about
218 .10 seconds. Type 3 is unimplemented and is 0.
219
220 Tab delay type 1 is dependent on the amount of movement and is tuned to
221 the Teletype model 37. Type 3, called XTABS, is not a delay at all but
222 causes tabs to be replaced by the appropriate number of spaces on out‐
223 put.
224
225 Characters with the wrong parity, as determined by bits 200 and 100,
226 are ignored.
227
228 In raw mode, every character is passed immediately to the program with‐
229 out waiting until a full line has been typed. No erase or kill pro‐
230 cessing is done; the end-of-file indicator (EOT), the interrupt charac‐
231 ter (DEL) and the quit character (FS) are not treated specially. There
232 are no delays and no echoing, and no replacement of one character for
233 another; characters are a full 8 bits for both input and output (parity
234 is up to the program).
235
236 Mode 020 causes input carriage returns to be turned into new-lines;
237 input of either CR or LF causes LF-CR both to be echoed (for terminals
238 with a new-line function).
239
240 CBREAK is a sort of half-cooked (rare?) mode. Programs can read each
241 character as soon as typed, instead of waiting for a full line, but
242 quit and interrupt work, and output delays, case-translation, CRMOD,
243 XTABS, ECHO, and parity work normally. On the other hand there is no
244 erase or kill, and no special treatment of \ or EOT.
245
246 TANDEM mode causes the system to produce a stop character (default DC3)
247 whenever the input queue is in danger of overflowing, and a start char‐
248 acter (default DC1) when the input queue has drained sufficiently. It
249 is useful for flow control when the `terminal' is actually another
250 machine that obeys the conventions.
251
252 Several ioctl calls have the form:
253
254 #include <sgtty.h>
255
256 ioctl(fildes, code, arg)
257 struct sgttyb *arg;
258
259 The applicable codes are:
260
261 TIOCGETP
262 Fetch the parameters associated with the terminal, and store in
263 the pointed-to structure.
264
265 TIOCSETP
266 Set the parameters according to the pointed-to structure. The
267 interface delays until output is quiescent, then throws away any
268 unread characters, before changing the modes.
269
270 TIOCSETN
271 Set the parameters but do not delay or flush input. Switching
272 out of RAW or CBREAK mode may cause some garbage input.
273
274 With the following codes the arg is ignored.
275
276 TIOCEXCL
277 Set ``exclusive-use'' mode: no further opens are permitted until
278 the file has been closed.
279
280 TIOCNXCL
281 Turn off ``exclusive-use'' mode.
282
283 TIOCHPCL
284 When the file is closed for the last time, hang up the terminal.
285 This is useful when the line is associated with an ACU used to
286 place outgoing calls.
287
288 TIOCFLUSH
289 All characters waiting in input or output queues are flushed.
290
291 The following codes affect characters that are special to the terminal
292 interface. The argument is a pointer to the following structure,
293 defined in <sgtty.h>:
294
295 struct tchars {
296 char t_intrc; /* interrupt */
297 char t_quitc; /* quit */
298 char t_startc; /* start output */
299 char t_stopc; /* stop output */
300 char t_eofc; /* end-of-file */
301 char t_brkc; /* input delimiter (like nl) */
302 };
303
304 The default values for these characters are DEL, FS, DC1, DC3, EOT, and
305 -1. A character value of -1 eliminates the effect of that character.
306 The t_brkc character, by default -1, acts like a new-line in that it
307 terminates a `line,' is echoed, and is passed to the program. The
308 `stop' and `start' characters may be the same, to produce a toggle
309 effect. It is probably counterproductive to make other special charac‐
310 ters (including erase an kill) identical.
311
312 The calls are:
313
314 TIOCSETC
315 Change the various special characters to those given in the
316 structure.
317
318 TIOCSETP
319 Set the special characters to those given in the structure.
320
322 /dev/tty
323 /dev/tty*
324 /dev/console
325
327 getty(8), stty (1), signal(2), ioctl(2)
328
330 Half-duplex terminals are not supported.
331
332 The terminal handler has clearly entered the race for ever-greater com‐
333 plexity and generality. It's still not complex and general enough for
334 TENEX fans.
335
336
337
338 TTY(4)