1 | .TH TTY 4
|
---|
2 | .SH NAME
|
---|
3 | tty, termios \- terminals
|
---|
4 | .SH DESCRIPTION
|
---|
5 | The
|
---|
6 | .B tty
|
---|
7 | driver family takes care of all user input and output. It governs the
|
---|
8 | keyboard, the console, the serial lines, and pseudo ttys. Input on any of
|
---|
9 | these devices undergoes "input processing", and output undergoes "output
|
---|
10 | processing" according to the standard termios terminal interface.
|
---|
11 | .SS "Input processing"
|
---|
12 | Each terminal device has an input queue. This queue is used to store
|
---|
13 | preprocessed input characters, and to perform the backspacing and erase
|
---|
14 | functions. Some special characters like a newline make the contents of the
|
---|
15 | queue available to a process reading from the terminal. Characters up to
|
---|
16 | and including the newline, or another so-called "line break", may be read by
|
---|
17 | a process. The process need not read all characters at once. An input line
|
---|
18 | may be read byte by byte if one wants to. A line break just makes
|
---|
19 | characters available for reading, thats all.
|
---|
20 | .PP
|
---|
21 | When data is made available depends on whether the tty is in canonical mode
|
---|
22 | or not. In canonical mode the terminal processes input line by line. A
|
---|
23 | line ends with a newline
|
---|
24 | .RB ( NL ),
|
---|
25 | end-of-file
|
---|
26 | .RB ( EOF ),
|
---|
27 | or end-of-line
|
---|
28 | .RB ( EOL ).
|
---|
29 | Characters that have not been delimited by such a line break may be erased
|
---|
30 | one by one with the
|
---|
31 | .B ERASE
|
---|
32 | character or all at once with the
|
---|
33 | .B KILL
|
---|
34 | character. Once a line break is typed the characters become available to a
|
---|
35 | reading process and can no longer be erased. Once read they are removed
|
---|
36 | from the input queue. Several lines may be gathered in the input queue if
|
---|
37 | no reader is present to read them, but a new reader will only receive one
|
---|
38 | line. Two line breaks are never returned in one read call. The input queue
|
---|
39 | has a maximum length of
|
---|
40 | .B MAX_CANON
|
---|
41 | characters. Any more characters are discarded. One must use
|
---|
42 | .B ERASE
|
---|
43 | or
|
---|
44 | .B KILL
|
---|
45 | to make the terminal functioning again if the input queue fills up. If
|
---|
46 | nonblocking I/O is set then \-1 is returned with
|
---|
47 | .B errno
|
---|
48 | set to
|
---|
49 | .B EAGAIN
|
---|
50 | if the reader would otherwise be blocked.
|
---|
51 | .PP
|
---|
52 | In non-canonical mode (raw mode for short) all characters are immediately
|
---|
53 | available to the reader in principle. One may however tune the terminal to
|
---|
54 | bursty input with the
|
---|
55 | .B MIN
|
---|
56 | and
|
---|
57 | .B TIME
|
---|
58 | parameters, see the raw I/O parameters section below. In raw mode no
|
---|
59 | characters are discarded if the input queue threatens to overflow if the
|
---|
60 | device supports flow control.
|
---|
61 | .SS "Output processing"
|
---|
62 | Characters written to a terminal device may undergo output processing, which
|
---|
63 | is usually just inserting a carriage returns before newlines. A writer
|
---|
64 | may return before all characters are output if the characters can be stored
|
---|
65 | in the output buffers. If not then the writer may be blocked until space is
|
---|
66 | available. If non-blocking I/O is set then only the count of the number of
|
---|
67 | bytes that can be processed immediately is returned. If no characters can
|
---|
68 | be written at all then \-1 is returned with
|
---|
69 | .B errno
|
---|
70 | set to
|
---|
71 | .BR EAGAIN .
|
---|
72 | .SS "Special characters"
|
---|
73 | Some characters have special functions in some of the terminal modes. These
|
---|
74 | characters are as follows, with the MINIX 3 defaults shown in parentheses:
|
---|
75 | .TP 5
|
---|
76 | .BR INTR " (^?)"
|
---|
77 | Special input character that is recognized if
|
---|
78 | .B ISIG
|
---|
79 | is set. (For
|
---|
80 | .B ISIG
|
---|
81 | and other flags see the various modes sections below.) It causes a
|
---|
82 | .B SIGINT
|
---|
83 | signal to be sent to all processes in the terminal process group. (See the
|
---|
84 | section on session leaders below.)
|
---|
85 | .TP
|
---|
86 | .BR QUIT " (^\e)"
|
---|
87 | Special input character if
|
---|
88 | .B ISIG
|
---|
89 | is set. Causes a
|
---|
90 | .B SIGQUIT
|
---|
91 | signal to be sent to the terminal process group.
|
---|
92 | .TP
|
---|
93 | .BR ERASE " (^H)"
|
---|
94 | Special input character if
|
---|
95 | .B ICANON
|
---|
96 | is set. Erases the last character in the current line.
|
---|
97 | .TP
|
---|
98 | .BR KILL " (^U)"
|
---|
99 | Special input character if
|
---|
100 | .B ICANON
|
---|
101 | is set. Erases the entire line.
|
---|
102 | .TP
|
---|
103 | .BR EOF " (^D)"
|
---|
104 | Special input character if
|
---|
105 | .B ICANON
|
---|
106 | is set. It is a line break character that is not itself returned to a
|
---|
107 | reader. If EOF is typed with no input present then the read returns zero,
|
---|
108 | which normally causes the reader to assume that end-of-file is reached.
|
---|
109 | .TP
|
---|
110 | .BR CR " (^M)"
|
---|
111 | Special input character if
|
---|
112 | .B IGNCR
|
---|
113 | or
|
---|
114 | .B ICRNL
|
---|
115 | is set. It is a carriage return ('\er'). If
|
---|
116 | .B IGNCR
|
---|
117 | is set then
|
---|
118 | .B CR
|
---|
119 | is discarded. If
|
---|
120 | .B ICRNL
|
---|
121 | is set and
|
---|
122 | .B IGNCR
|
---|
123 | is not set then
|
---|
124 | .B CR
|
---|
125 | is changed into an
|
---|
126 | .B NL
|
---|
127 | and has the same function as
|
---|
128 | .BR NL.
|
---|
129 | .TP
|
---|
130 | .BR NL " (^J)"
|
---|
131 | Special input character if
|
---|
132 | .B ICANON
|
---|
133 | is set. It is both a newline ('\en') and a line break.
|
---|
134 | .br
|
---|
135 | Special output character if
|
---|
136 | .B OPOST
|
---|
137 | and
|
---|
138 | .B ONLCR
|
---|
139 | are set. A
|
---|
140 | .B CR NL
|
---|
141 | sequence is output instead of just
|
---|
142 | .BR NL .
|
---|
143 | (MINIX 3 specific, but almost mandatory on any UNIX-like system.)
|
---|
144 | .TP
|
---|
145 | .BR TAB " (^I)"
|
---|
146 | Special character on output if
|
---|
147 | .B OPOST
|
---|
148 | and
|
---|
149 | .B XTABS
|
---|
150 | are set. It is transformed into the number of spaces necessary to reach a
|
---|
151 | column position that is a multiple of eight. (Only needed for terminals
|
---|
152 | without hardware tabs.)
|
---|
153 | .TP
|
---|
154 | .BR EOL " (undefined)"
|
---|
155 | Special input character if
|
---|
156 | .B ICANON
|
---|
157 | is set. It is an additional line break.
|
---|
158 | .TP
|
---|
159 | .BR SUSP " (^Z)"
|
---|
160 | Special input character if job control is implemented and
|
---|
161 | .B ISIG
|
---|
162 | is set. It causes a
|
---|
163 | .B SIGTSTP
|
---|
164 | signal to be send to the terminal process group. (MINIX 3 does not have job
|
---|
165 | control.)
|
---|
166 | .TP
|
---|
167 | .BR STOP " (^S)"
|
---|
168 | Special input character if
|
---|
169 | .B IXON
|
---|
170 | is set. It suspends terminal output and is then discarded.
|
---|
171 | .TP
|
---|
172 | .BR START " (^Q)"
|
---|
173 | Special output character if
|
---|
174 | .B IXON
|
---|
175 | is set. It starts terminal output if suspended and is then discarded. If
|
---|
176 | .B IXANY
|
---|
177 | is also set then any other character also starts terminal output, but they
|
---|
178 | are not discarded.
|
---|
179 | .TP
|
---|
180 | .BR REPRINT " (^R)"
|
---|
181 | Special input character if
|
---|
182 | .B IEXTEN
|
---|
183 | and
|
---|
184 | .B ECHO
|
---|
185 | are set. Reprints the input queue from the last line break onwards. A
|
---|
186 | reprint also happens automatically if the echoed input has been messed up by
|
---|
187 | other output and
|
---|
188 | .B ERASE
|
---|
189 | is typed.
|
---|
190 | .TP
|
---|
191 | .BR LNEXT " (^V)"
|
---|
192 | Special input character if
|
---|
193 | .B IEXTEN
|
---|
194 | is set. It is the "literal next" character that causes the next character
|
---|
195 | to be input without any special processing.
|
---|
196 | .TP
|
---|
197 | .BR DISCARD " (^O)"
|
---|
198 | Special input character if
|
---|
199 | .B IEXTEN
|
---|
200 | is set. Causes output to be discarded until it is typed again. (Implemented
|
---|
201 | only under Minix-vmd.)
|
---|
202 | .PP
|
---|
203 | All of these characters except
|
---|
204 | .BR CR ,
|
---|
205 | .B NL
|
---|
206 | and
|
---|
207 | .B TAB
|
---|
208 | may be changed or disabled under MINIX 3. (Changes to
|
---|
209 | .B START
|
---|
210 | and
|
---|
211 | .B STOP
|
---|
212 | may be ignored under other termios implementations.) The
|
---|
213 | .B REPRINT
|
---|
214 | and
|
---|
215 | .B LNEXT
|
---|
216 | characters are MINIX 3 extensions that are commonly present in other
|
---|
217 | implementations. \s-2POSIX\s+2 is unclear on whether
|
---|
218 | .BR IEXTEN,
|
---|
219 | .BR IGNCR
|
---|
220 | and
|
---|
221 | .BR ICRNL
|
---|
222 | should be active in non-canonical mode, but under MINIX 3 they are.
|
---|
223 | .SS "Terminal attributes"
|
---|
224 | The attributes of a terminal, such as whether the mode should be canonical or
|
---|
225 | non-canonical, are controlled by routines that use the
|
---|
226 | .B termios
|
---|
227 | structure as defined in
|
---|
228 | .BR <termios.h> :
|
---|
229 | .PP
|
---|
230 | .RS
|
---|
231 | .nf
|
---|
232 | .ta +4n +10n +15n
|
---|
233 | struct termios {
|
---|
234 | tcflag_t c_iflag; /* input modes */
|
---|
235 | tcflag_t c_oflag; /* output modes */
|
---|
236 | tcflag_t c_cflag; /* control modes */
|
---|
237 | tcflag_t c_lflag; /* local modes */
|
---|
238 | speed_t c_ispeed; /* input speed */
|
---|
239 | speed_t c_ospeed; /* output speed */
|
---|
240 | cc_t c_cc[NCCS]; /* control characters */
|
---|
241 | };
|
---|
242 | .fi
|
---|
243 | .RE
|
---|
244 | .PP
|
---|
245 | The types
|
---|
246 | .BR tcflag ,
|
---|
247 | .B speed_t
|
---|
248 | and
|
---|
249 | .B cc_t
|
---|
250 | are defined in
|
---|
251 | .B <termios.h>
|
---|
252 | as unsigned integral types.
|
---|
253 | .SS "Input Modes"
|
---|
254 | The
|
---|
255 | .B c_iflag
|
---|
256 | field contains the following single bit flags that control input processing:
|
---|
257 | .TP 5
|
---|
258 | .B ICRNL
|
---|
259 | Map
|
---|
260 | .B CR
|
---|
261 | to
|
---|
262 | .B NL
|
---|
263 | on input.
|
---|
264 | .TP
|
---|
265 | .B IGNCR
|
---|
266 | Ignore
|
---|
267 | .B CR
|
---|
268 | on input. This flag overrides
|
---|
269 | .BR ICRNL .
|
---|
270 | .TP
|
---|
271 | .B INLCR
|
---|
272 | Map
|
---|
273 | .B NL
|
---|
274 | to
|
---|
275 | .B CR
|
---|
276 | on input. This is done after the
|
---|
277 | .B IGNCR
|
---|
278 | check.
|
---|
279 | .TP
|
---|
280 | .B IXON
|
---|
281 | Enable start/stop output control.
|
---|
282 | .TP
|
---|
283 | .B IXOFF
|
---|
284 | Enable start/stop input control. (Not implemented.)
|
---|
285 | .TP
|
---|
286 | .B IXANY
|
---|
287 | Allow any character to restart output. (MINIX 3 specific.)
|
---|
288 | .TP
|
---|
289 | .B ISTRIP
|
---|
290 | Strip characters to seven bits.
|
---|
291 | .TP
|
---|
292 | .B IGNPAR
|
---|
293 | Ignore characters with parity errors. (Not implemented.)
|
---|
294 | .TP
|
---|
295 | .B INPCK
|
---|
296 | Enable input parity checking. (Not implemented.)
|
---|
297 | .TP
|
---|
298 | .B PARMRK
|
---|
299 | Mark parity errors by preceding the faulty character with '\e377', '\e0'.
|
---|
300 | The character '\e377' is preceded by another '\e377' to avoid ambiguity.
|
---|
301 | (Not implemented.)
|
---|
302 | .TP
|
---|
303 | .B BRKINT
|
---|
304 | Send the signal
|
---|
305 | .B SIGINT
|
---|
306 | to the terminal process group when receiving a break condition. (Not
|
---|
307 | implemented.)
|
---|
308 | .TP
|
---|
309 | .B IGNBRK
|
---|
310 | Ignore break condition. If neither
|
---|
311 | .B BRKINT
|
---|
312 | or
|
---|
313 | .B IGNBRK
|
---|
314 | is set a break is input as a single '\e0', or if
|
---|
315 | .B PARMRK
|
---|
316 | is set as '\e377', '\e0', '\e0'.
|
---|
317 | (Breaks are always ignored.)
|
---|
318 | .SS "Output Modes"
|
---|
319 | The
|
---|
320 | .B c_oflag
|
---|
321 | field contains the following single bit flags that control output processing:
|
---|
322 | .TP
|
---|
323 | .B OPOST
|
---|
324 | Perform output processing. This flag is the "main switch" on output
|
---|
325 | processing. All other flags are MINIX 3 specific.
|
---|
326 | .TP
|
---|
327 | .B ONLCR
|
---|
328 | Transform an
|
---|
329 | .B NL
|
---|
330 | to a
|
---|
331 | .B CR NL
|
---|
332 | sequence on output. Note that a key labeled "RETURN" or "ENTER" usually
|
---|
333 | sends a
|
---|
334 | .BR CR .
|
---|
335 | In line oriented mode this is normally transformed into
|
---|
336 | .B NL
|
---|
337 | by
|
---|
338 | .BR ICRNL .
|
---|
339 | .B NL
|
---|
340 | is the normal UNIX line delimiter ('\en'). On output an
|
---|
341 | .B NL
|
---|
342 | is transformed into the
|
---|
343 | .B CR NL
|
---|
344 | sequence that is necessary to reach the first column of the next line.
|
---|
345 | (This is a common output processing function for UNIX-like systems, but not
|
---|
346 | always separately switchable by an
|
---|
347 | .B ONLCR
|
---|
348 | flag.)
|
---|
349 | .TP
|
---|
350 | .B XTABS
|
---|
351 | Transform a
|
---|
352 | .B TAB
|
---|
353 | into the number of spaces necessary to reach a column position that is a
|
---|
354 | multiple of eight.
|
---|
355 | .TP
|
---|
356 | .B ONOEOT
|
---|
357 | Discard
|
---|
358 | .B EOT
|
---|
359 | (^D) characters. (Minix-vmd only.)
|
---|
360 | .SS "Control Modes"
|
---|
361 | The
|
---|
362 | .B c_cflag
|
---|
363 | field contains the following single bit flags and bit field for basic
|
---|
364 | hardware control:
|
---|
365 | .TP
|
---|
366 | .B CLOCAL
|
---|
367 | Ignore modem status lines.
|
---|
368 | .TP
|
---|
369 | .B CREAD
|
---|
370 | Enable receiver. (The receiver is always enabled.)
|
---|
371 | .TP
|
---|
372 | .B CSIZE
|
---|
373 | Number of bits per byte.
|
---|
374 | .B CSIZE
|
---|
375 | masks off the values
|
---|
376 | .BR CS5 ,
|
---|
377 | .BR CS6 ,
|
---|
378 | .BR CS7
|
---|
379 | and
|
---|
380 | .BR CS8
|
---|
381 | that indicate that 5, 6, 7 or 8 bits are used.
|
---|
382 | .TP
|
---|
383 | .B CSTOPB
|
---|
384 | Send two stop bits instead of one. Two stop bits are normally used at 110
|
---|
385 | baud or less.
|
---|
386 | .TP
|
---|
387 | .B PARENB
|
---|
388 | Enable parity generation.
|
---|
389 | .TP
|
---|
390 | .B PARODD
|
---|
391 | Generate odd parity if parity is generated, otherwise even parity.
|
---|
392 | .TP
|
---|
393 | .B HUPCL
|
---|
394 | Drop the modem control lines on the last close of the terminal line. (Not
|
---|
395 | implemented.)
|
---|
396 | .SS "Local Modes"
|
---|
397 | The
|
---|
398 | .B c_lflag
|
---|
399 | field contains the following single bit flags that control various functions:
|
---|
400 | .TP
|
---|
401 | .B ECHO
|
---|
402 | Enable echoing of input characters. Most input characters are echoed as
|
---|
403 | they are. Control characters are echoed as
|
---|
404 | .BI "^" X
|
---|
405 | where
|
---|
406 | .I X
|
---|
407 | is the letter used to say that the control character is
|
---|
408 | .BI CTRL\- X\fR.
|
---|
409 | The
|
---|
410 | .BR CR ,
|
---|
411 | .BR NL
|
---|
412 | and
|
---|
413 | .BR TAB
|
---|
414 | characters are echoed with their normal effect unless they are escaped by
|
---|
415 | .BR LNEXT .
|
---|
416 | .TP
|
---|
417 | .B ECHOE
|
---|
418 | If
|
---|
419 | .B ICANON
|
---|
420 | and
|
---|
421 | .B ECHO
|
---|
422 | are set then echo
|
---|
423 | .B ERASE
|
---|
424 | and
|
---|
425 | .B KILL
|
---|
426 | as one or more backspace-space-backspace sequences to wipe out the last
|
---|
427 | character or the entire line, otherwise they are echoed as they are.
|
---|
428 | .TP
|
---|
429 | .B ECHOK
|
---|
430 | If
|
---|
431 | .B ICANON
|
---|
432 | and
|
---|
433 | .B ECHO
|
---|
434 | are set and
|
---|
435 | .B ECHOE
|
---|
436 | is not set then output an
|
---|
437 | .B NL
|
---|
438 | after the
|
---|
439 | .B KILL
|
---|
440 | character. (For hardcopy terminals it is best to unset
|
---|
441 | .B ECHOE
|
---|
442 | and to set
|
---|
443 | .BR ECHOK .)
|
---|
444 | .TP
|
---|
445 | .B ECHONL
|
---|
446 | Echo
|
---|
447 | .B NL
|
---|
448 | even if
|
---|
449 | .B ECHO
|
---|
450 | is not set, but
|
---|
451 | .B ICANON
|
---|
452 | is set.
|
---|
453 | .TP
|
---|
454 | .B ICANON
|
---|
455 | Canonical input. This enables line oriented input and erase and kill
|
---|
456 | processing.
|
---|
457 | .TP
|
---|
458 | .B IEXTEN
|
---|
459 | Enable implementation defined input extensions.
|
---|
460 | .TP
|
---|
461 | .B ISIG
|
---|
462 | Enable the signal characters
|
---|
463 | .BR INTR ,
|
---|
464 | .BR QUIT
|
---|
465 | and
|
---|
466 | .BR SUSP .
|
---|
467 | .TP
|
---|
468 | .B NOFLSH
|
---|
469 | Disable the flushing of the input and output queues that is normally done if
|
---|
470 | a signal is sent.
|
---|
471 | .TP
|
---|
472 | .B TOSTOP
|
---|
473 | Send a
|
---|
474 | .B SIGTTOU
|
---|
475 | signal if job control is implemented and a background process tries to
|
---|
476 | write. (MINIX 3 has no job control.)
|
---|
477 | .SS "Input and output speed"
|
---|
478 | The input and output speed are encoded into the
|
---|
479 | .B c_ispeed
|
---|
480 | and
|
---|
481 | .B c_ospeed
|
---|
482 | fields.
|
---|
483 | .B <termios.h>
|
---|
484 | defines the symbols
|
---|
485 | .BR B0 ,
|
---|
486 | .BR B50 ,
|
---|
487 | .BR B75 ,
|
---|
488 | .BR B110 ,
|
---|
489 | .BR B134 ,
|
---|
490 | .BR B150 ,
|
---|
491 | .BR B200 ,
|
---|
492 | .BR B300 ,
|
---|
493 | .BR B600 ,
|
---|
494 | .BR B1200 ,
|
---|
495 | .BR B1800 ,
|
---|
496 | .BR B2400 ,
|
---|
497 | .BR B4800 ,
|
---|
498 | .BR B9600 ,
|
---|
499 | .BR B19200 ,
|
---|
500 | .BR B38400 ,
|
---|
501 | .BR B57600
|
---|
502 | and
|
---|
503 | .BR B115200
|
---|
504 | as values used to indicate the given baud rates. The zero baud rate,
|
---|
505 | .BR B0 ,
|
---|
506 | if used for the input speed causes the input speed to be equal to the
|
---|
507 | output speed. Setting the output speed to zero hangs up the line. One
|
---|
508 | should use the functions
|
---|
509 | .BR cfgetispeed() ,
|
---|
510 | .BR cfgetospeed() ,
|
---|
511 | .BR cfsetispeed()
|
---|
512 | and
|
---|
513 | .BR cfsetospeed()
|
---|
514 | to get or set a speed, because the
|
---|
515 | .B c_ispeed
|
---|
516 | and
|
---|
517 | .B c_ospeed
|
---|
518 | fields may not be visible under other implementations. (The
|
---|
519 | .B c_ispeed
|
---|
520 | and
|
---|
521 | .B c_ospeed
|
---|
522 | fields and the
|
---|
523 | .B B57600
|
---|
524 | and
|
---|
525 | .B B115200
|
---|
526 | symbols are MINIX 3 specific.)
|
---|
527 | .SS "Special characters"
|
---|
528 | The
|
---|
529 | .B c_cc
|
---|
530 | array contains the special characters that can be modified. The array has
|
---|
531 | length
|
---|
532 | .B NCCS
|
---|
533 | and is subscripted by the symbols
|
---|
534 | .BR VEOF ,
|
---|
535 | .BR VEOL ,
|
---|
536 | .BR VERASE ,
|
---|
537 | .BR VINTR ,
|
---|
538 | .BR VKILL ,
|
---|
539 | .BR VMIN ,
|
---|
540 | .BR VQUIT ,
|
---|
541 | .BR VTIME ,
|
---|
542 | .BR VSUSP ,
|
---|
543 | .BR VSTART ,
|
---|
544 | .BR VSTOP ,
|
---|
545 | .BR VREPRINT ,
|
---|
546 | .BR VLNEXT
|
---|
547 | and
|
---|
548 | .BR VDISCARD .
|
---|
549 | All these symbols are defined in
|
---|
550 | .BR <termios.h> .
|
---|
551 | Some implementations may give the same values to the
|
---|
552 | .B VMIN
|
---|
553 | and
|
---|
554 | .B VTIME
|
---|
555 | subscripts and the
|
---|
556 | .B VEOF
|
---|
557 | and
|
---|
558 | .B VEOL
|
---|
559 | subscripts respectively, and may ignore changes to
|
---|
560 | .B START
|
---|
561 | and
|
---|
562 | .BR STOP .
|
---|
563 | (Under MINIX 3 all special characters have their own
|
---|
564 | .I c_cc
|
---|
565 | slot and can all be modified.)
|
---|
566 | .SS "Raw I/O Parameters"
|
---|
567 | The
|
---|
568 | .B MIN
|
---|
569 | and
|
---|
570 | .B TIME
|
---|
571 | parameters can be used to adjust a raw connection to bursty input.
|
---|
572 | .B MIN
|
---|
573 | represents a minimum number of bytes that must be received before a read
|
---|
574 | call returns.
|
---|
575 | .B TIME
|
---|
576 | is a timer of 0.1 second granularity that can be used to time out a read.
|
---|
577 | Setting either of these parameters to zero has special meaning, which leads
|
---|
578 | to the following four possibilities:
|
---|
579 | .TP 5
|
---|
580 | .B "MIN > 0, TIME > 0"
|
---|
581 | .B TIME
|
---|
582 | is an inter-byte timer that is started (and restarted) when a byte is
|
---|
583 | received. A read succeeds when either the minimum number of characters
|
---|
584 | is received or the timer expires. Note that the timer starts
|
---|
585 | .B after
|
---|
586 | the first character, so the read returns at least one byte.
|
---|
587 | .TP
|
---|
588 | .B "MIN > 0, TIME = 0"
|
---|
589 | Now the timer is disabled, and a reader blocks indefinitely until at least
|
---|
590 | .B MIN
|
---|
591 | characters are received.
|
---|
592 | .TP
|
---|
593 | .B "MIN = 0, TIME > 0"
|
---|
594 | .B TIME
|
---|
595 | is now a read timer that is started when a read is executed. The read will
|
---|
596 | return if the read timer expires or if at least one byte is input. (Note
|
---|
597 | that a value of zero may be returned to the reader.)
|
---|
598 | .TP
|
---|
599 | .B "MIN = 0, TIME = 0"
|
---|
600 | The bytes currently available are returned. Zero is returned if no bytes
|
---|
601 | are available.
|
---|
602 | .SS "User Level Functions"
|
---|
603 | Termios attributes are set or examined, and special functions can be
|
---|
604 | performed by using the functions described in
|
---|
605 | .BR termios (3).
|
---|
606 | .SS "Session Leaders and Process Groups"
|
---|
607 | With the use of the
|
---|
608 | .B setsid()
|
---|
609 | function can a process become a session leader. A session leader forms a
|
---|
610 | process group with a process group id equal to the process id of the session
|
---|
611 | leader. If a session leader opens a terminal device file then this terminal
|
---|
612 | becomes the controlling tty of the session leader. Unless the terminal is
|
---|
613 | already the controlling tty of another process, or unless the
|
---|
614 | .B O_NOCTTY
|
---|
615 | flag is used to prevent the allocation of a controlling tty. The process
|
---|
616 | group of the session leader is now remembered as the terminal process group
|
---|
617 | for signals sent by the terminal driver. All the children and grandchildren
|
---|
618 | of the session leader inherit the controlling terminal and process group
|
---|
619 | until they themselves use
|
---|
620 | .BR setsid() .
|
---|
621 | .PP
|
---|
622 | The controlling tty becomes inaccessible to the children of the session
|
---|
623 | leader when the session leader exits, and a hangup signal is sent to all
|
---|
624 | the members of the process group. The input and output queues are flushed
|
---|
625 | on the last close of a terminal and all attributes are reset to the default
|
---|
626 | state.
|
---|
627 | .PP
|
---|
628 | A special device
|
---|
629 | .B /dev/tty
|
---|
630 | is a synonym for the controlling tty of a process. It allows a process to
|
---|
631 | reach the terminal even when standard input, output and error are
|
---|
632 | redirected. Opening this device can also be used as a test to see if a
|
---|
633 | process has a controlling tty or not.
|
---|
634 | .PP
|
---|
635 | For MINIX 3 a special write-only device
|
---|
636 | .B /dev/log
|
---|
637 | exists for processes that want to write messages to the system console.
|
---|
638 | Unlike the console this device is still accessible when a session leader
|
---|
639 | exits.
|
---|
640 | .PP
|
---|
641 | Minix-vmd also has a
|
---|
642 | .B /dev/log
|
---|
643 | device, but this device is read-write. All messages written to the log
|
---|
644 | device or to the console when X11 is active can be read from
|
---|
645 | .BR /dev/log .
|
---|
646 | The system tries to preserve the log buffer over a reboot so that panic
|
---|
647 | messages reappear in the log if the system happens to crash.
|
---|
648 | .SS "Pseudo Terminals"
|
---|
649 | Pseudo ttys allow a process such as a remote login daemon to set up a
|
---|
650 | terminal for a remote login session. The login session uses a device like
|
---|
651 | .B /dev/ttyp0
|
---|
652 | for input and output, and the remote login daemon uses the device
|
---|
653 | .B /dev/ptyp0
|
---|
654 | to supply input to or take output from the login session and transfer this
|
---|
655 | to or from the originating system. So the character flow may be: Local
|
---|
656 | user input sent to the remote system is written to
|
---|
657 | .B /dev/ptyp0
|
---|
658 | by the remote login daemon, undergoes input processing and appears on
|
---|
659 | .B /dev/ttyp0
|
---|
660 | as input to the login session. Output from the login session to
|
---|
661 | .B /dev/ttyp0
|
---|
662 | undergoes output processing, is read from
|
---|
663 | .B /dev/ptyp0
|
---|
664 | by the remote login daemon and is send over to the local system to be
|
---|
665 | displayed for the user. (So there are only four data streams to worry about
|
---|
666 | in a pseudo terminal.)
|
---|
667 | .PP
|
---|
668 | A pseudo terminal can be allocated by trying to open all the controlling
|
---|
669 | devices
|
---|
670 | .BI /dev/pty nn
|
---|
671 | one by one until it succeeds. Further opens will fail once a pty is open.
|
---|
672 | The process should now fork, the child should become session leader, open
|
---|
673 | the tty side of the pty and start a login session.
|
---|
674 | .PP
|
---|
675 | If the tty side is eventually closed down then reads from the pty side will
|
---|
676 | return zero and writes return \-1 with
|
---|
677 | .B errno
|
---|
678 | set to
|
---|
679 | .BR EIO .
|
---|
680 | If the pty side is closed first then a
|
---|
681 | .B SIGHUP
|
---|
682 | signal is sent to the session leader and further reads from the tty side
|
---|
683 | return zero and writes return \-1 with
|
---|
684 | .B errno
|
---|
685 | set to
|
---|
686 | .BR EIO .
|
---|
687 | (Special note: A line erase may cause up to three times the size of the
|
---|
688 | tty input queue to be sent to the pty reader as backspace overstrikes. Some
|
---|
689 | of this output may get lost if the pty reader cannot accept it all at once
|
---|
690 | in a single read call.)
|
---|
691 | .SS "Backwards compatibility"
|
---|
692 | The
|
---|
693 | .BR TIOCGETP ,
|
---|
694 | .BR TIOCSETP ,
|
---|
695 | .BR TIOCGETC
|
---|
696 | and
|
---|
697 | .BR TIOCSETC
|
---|
698 | ioctl functions that are used by the old
|
---|
699 | .B sgtty
|
---|
700 | terminal interface are still supported by the terminal driver by emulation.
|
---|
701 | Note that these old functions cannot control all termios attributes, so the
|
---|
702 | terminal must be in a relatively sane state to avoid problems.
|
---|
703 | .SH FILES
|
---|
704 | The list below shows all devices that MINIX 3 and Minix-vmd have. Not all of
|
---|
705 | these devices are configured in by default, as indicated by the numbers
|
---|
706 | (i/j/k, l/m/n) that tell the minimum, default and maximum possible number of
|
---|
707 | these devices for MINIX 3 (i/j/k) and Minix-vmd (l/m/n).
|
---|
708 | .TP 20
|
---|
709 | .B /dev/console
|
---|
710 | System console.
|
---|
711 | .TP
|
---|
712 | .B /dev/ttyc[1-7]
|
---|
713 | Virtual consoles. (0/1/7, 0/1/7)
|
---|
714 | .TP
|
---|
715 | .BR /dev/log
|
---|
716 | Console log device.
|
---|
717 | .TP
|
---|
718 | .B /dev/tty0[0-3]
|
---|
719 | Serial lines. (0/2/2, 4/4/4)
|
---|
720 | .TP
|
---|
721 | .B /dev/tty[p-w][0-f]
|
---|
722 | Pseudo ttys. (0/0/64, 1/32/128)
|
---|
723 | .TP
|
---|
724 | .B /dev/pty[p-w][0-f]
|
---|
725 | Associated pseudo tty controllers.
|
---|
726 | .SH "SEE ALSO"
|
---|
727 | .BR stty (1),
|
---|
728 | .BR termios (3),
|
---|
729 | .BR setsid (2),
|
---|
730 | .BR read (2),
|
---|
731 | .BR write (2).
|
---|
732 | .SH BUGS
|
---|
733 | A fair number of flags are not implemented under MINIX 3 (yet). Luckily they
|
---|
734 | are very limited utility and only apply to RS-232, not to the user interface.
|
---|
735 | .SH AUTHOR
|
---|
736 | Kees J. Bot (kjb@cs.vu.nl)
|
---|