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