3 tty, termios \- terminals
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.
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
29 Characters that have not been delimited by such a line break may be erased
32 character or all at once with the
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
41 characters. Any more characters are discarded. One must use
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
50 if the reader would otherwise be blocked.
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
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
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:
77 Special input character that is recognized if
81 and other flags see the various modes sections below.) It causes a
83 signal to be sent to all processes in the terminal process group. (See the
84 section on session leaders below.)
87 Special input character if
91 signal to be sent to the terminal process group.
94 Special input character if
96 is set. Erases the last character in the current line.
99 Special input character if
101 is set. Erases the entire line.
104 Special input character if
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.
111 Special input character if
115 is set. It is a carriage return ('\er'). If
127 and has the same function as
131 Special input character if
133 is set. It is both a newline ('\en') and a line break.
135 Special output character if
141 sequence is output instead of just
143 (MINIX 3 specific, but almost mandatory on any UNIX-like system.)
146 Special character on output if
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.)
154 .BR EOL " (undefined)"
155 Special input character if
157 is set. It is an additional line break.
160 Special input character if job control is implemented and
164 signal to be send to the terminal process group. (MINIX 3 does not have job
168 Special input character if
170 is set. It suspends terminal output and is then discarded.
173 Special output character if
175 is set. It starts terminal output if suspended and is then discarded. If
177 is also set then any other character also starts terminal output, but they
181 Special input character if
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
192 Special input character if
194 is set. It is the "literal next" character that causes the next character
195 to be input without any special processing.
198 Special input character if
200 is set. Causes output to be discarded until it is typed again. (Implemented
201 only under Minix-vmd.)
203 All of these characters except
208 may be changed or disabled under MINIX 3. (Changes to
212 may be ignored under other termios implementations.) The
216 characters are MINIX 3 extensions that are commonly present in other
217 implementations. \s-2POSIX\s+2 is unclear on whether
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
227 structure as defined in
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 */
252 as unsigned integral types.
256 field contains the following single bit flags that control input processing:
268 on input. This flag overrides
276 on input. This is done after the
281 Enable start/stop output control.
284 Enable start/stop input control. (Not implemented.)
287 Allow any character to restart output. (MINIX 3 specific.)
290 Strip characters to seven bits.
293 Ignore characters with parity errors. (Not implemented.)
296 Enable input parity checking. (Not implemented.)
299 Mark parity errors by preceding the faulty character with '\e377', '\e0'.
300 The character '\e377' is preceded by another '\e377' to avoid ambiguity.
306 to the terminal process group when receiving a break condition. (Not
310 Ignore break condition. If neither
314 is set a break is input as a single '\e0', or if
316 is set as '\e377', '\e0', '\e0'.
317 (Breaks are always ignored.)
320 Send input as keyboard scancodes rather than processed ASCII characters. This
321 flag only applies to consoles; to check whether the flag is supported use the
323 function after setting it and test whether
327 flag. Scancodes are provided directly and without any processing. As a
340 flags no longer influence input if this flag is specified. However, they may
341 still influence echoing if enabled. (MINIX 3 specific.)
345 field contains the following single bit flags that control output processing:
348 Perform output processing. This flag is the "main switch" on output
349 processing. All other flags are MINIX 3 specific.
356 sequence on output. Note that a key labeled "RETURN" or "ENTER" usually
359 In line oriented mode this is normally transformed into
364 is the normal UNIX line delimiter ('\en'). On output an
366 is transformed into the
368 sequence that is necessary to reach the first column of the next line.
369 (This is a common output processing function for UNIX-like systems, but not
370 always separately switchable by an
377 into the number of spaces necessary to reach a column position that is a
383 (^D) characters. (Minix-vmd only.)
387 field contains the following single bit flags and bit field for basic
391 Ignore modem status lines.
394 Enable receiver. (The receiver is always enabled.)
397 Number of bits per byte.
405 that indicate that 5, 6, 7 or 8 bits are used.
408 Send two stop bits instead of one. Two stop bits are normally used at 110
412 Enable parity generation.
415 Generate odd parity if parity is generated, otherwise even parity.
418 Drop the modem control lines on the last close of the terminal line. (Not
423 field contains the following single bit flags that control various functions:
426 Enable echoing of input characters. Most input characters are echoed as
427 they are. Control characters are echoed as
431 is the letter used to say that the control character is
438 characters are echoed with their normal effect unless they are escaped by
450 as one or more backspace-space-backspace sequences to wipe out the last
451 character or the entire line, otherwise they are echoed as they are.
460 is not set then output an
464 character. (For hardcopy terminals it is best to unset
479 Canonical input. This enables line oriented input and erase and kill
483 Enable implementation defined input extensions.
486 Enable the signal characters
493 Disable the flushing of the input and output queues that is normally done if
499 signal if job control is implemented and a background process tries to
500 write. (MINIX 3 has no job control.)
501 .SS "Input and output speed"
502 The input and output speed are encoded into the
528 as values used to indicate the given baud rates. The zero baud rate,
530 if used for the input speed causes the input speed to be equal to the
531 output speed. Setting the output speed to zero hangs up the line. One
532 should use the functions
538 to get or set a speed, because the
542 fields may not be visible under other implementations. (The
550 symbols are MINIX 3 specific.)
551 .SS "Special characters"
554 array contains the special characters that can be modified. The array has
557 and is subscripted by the symbols
573 All these symbols are defined in
575 Some implementations may give the same values to the
583 subscripts respectively, and may ignore changes to
587 (Under MINIX 3 all special characters have their own
589 slot and can all be modified.)
590 .SS "Raw I/O Parameters"
595 parameters can be used to adjust a raw connection to bursty input.
597 represents a minimum number of bytes that must be received before a read
600 is a timer of 0.1 second granularity that can be used to time out a read.
601 Setting either of these parameters to zero has special meaning, which leads
602 to the following four possibilities:
604 .B "MIN > 0, TIME > 0"
606 is an inter-byte timer that is started (and restarted) when a byte is
607 received. A read succeeds when either the minimum number of characters
608 is received or the timer expires. Note that the timer starts
610 the first character, so the read returns at least one byte.
612 .B "MIN > 0, TIME = 0"
613 Now the timer is disabled, and a reader blocks indefinitely until at least
615 characters are received.
617 .B "MIN = 0, TIME > 0"
619 is now a read timer that is started when a read is executed. The read will
620 return if the read timer expires or if at least one byte is input. (Note
621 that a value of zero may be returned to the reader.)
623 .B "MIN = 0, TIME = 0"
624 The bytes currently available are returned. Zero is returned if no bytes
626 .SS "User Level Functions"
627 Termios attributes are set or examined, and special functions can be
628 performed by using the functions described in
630 .SS "Session Leaders and Process Groups"
633 function can a process become a session leader. A session leader forms a
634 process group with a process group id equal to the process id of the session
635 leader. If a session leader opens a terminal device file then this terminal
636 becomes the controlling tty of the session leader. Unless the terminal is
637 already the controlling tty of another process, or unless the
639 flag is used to prevent the allocation of a controlling tty. The process
640 group of the session leader is now remembered as the terminal process group
641 for signals sent by the terminal driver. All the children and grandchildren
642 of the session leader inherit the controlling terminal and process group
643 until they themselves use
646 The controlling tty becomes inaccessible to the children of the session
647 leader when the session leader exits, and a hangup signal is sent to all
648 the members of the process group. The input and output queues are flushed
649 on the last close of a terminal and all attributes are reset to the default
654 is a synonym for the controlling tty of a process. It allows a process to
655 reach the terminal even when standard input, output and error are
656 redirected. Opening this device can also be used as a test to see if a
657 process has a controlling tty or not.
659 For MINIX 3 a special write-only device
661 exists for processes that want to write messages to the system console.
662 Unlike the console this device is still accessible when a session leader
667 device, but this device is read-write. All messages written to the log
668 device or to the console when X11 is active can be read from
670 The system tries to preserve the log buffer over a reboot so that panic
671 messages reappear in the log if the system happens to crash.
672 .SS "Pseudo Terminals"
673 Pseudo ttys allow a process such as a remote login daemon to set up a
674 terminal for a remote login session. The login session uses a device like
676 for input and output, and the remote login daemon uses the device
678 to supply input to or take output from the login session and transfer this
679 to or from the originating system. So the character flow may be: Local
680 user input sent to the remote system is written to
682 by the remote login daemon, undergoes input processing and appears on
684 as input to the login session. Output from the login session to
686 undergoes output processing, is read from
688 by the remote login daemon and is send over to the local system to be
689 displayed for the user. (So there are only four data streams to worry about
690 in a pseudo terminal.)
692 A pseudo terminal can be allocated by trying to open all the controlling
695 one by one until it succeeds. Further opens will fail once a pty is open.
696 The process should now fork, the child should become session leader, open
697 the tty side of the pty and start a login session.
699 If the tty side is eventually closed down then reads from the pty side will
700 return zero and writes return \-1 with
704 If the pty side is closed first then a
706 signal is sent to the session leader and further reads from the tty side
707 return zero and writes return \-1 with
711 (Special note: A line erase may cause up to three times the size of the
712 tty input queue to be sent to the pty reader as backspace overstrikes. Some
713 of this output may get lost if the pty reader cannot accept it all at once
714 in a single read call.)
716 The list below shows all devices that MINIX 3 and Minix-vmd have. Not all of
717 these devices are configured in by default, as indicated by the numbers
718 (i/j/k, l/m/n) that tell the minimum, default and maximum possible number of
719 these devices for MINIX 3 (i/j/k) and Minix-vmd (l/m/n).
725 Virtual consoles. (0/1/7, 0/1/7)
731 Serial lines. (0/2/2, 4/4/4)
733 .B /dev/tty[p-w][0-f]
734 Pseudo ttys. (0/0/64, 1/32/128)
736 .B /dev/pty[p-w][0-f]
737 Associated pseudo tty controllers.
745 A fair number of flags are not implemented under MINIX 3 (yet). Luckily they
746 are very limited utility and only apply to RS-232, not to the user interface.
748 Kees J. Bot (kjb@cs.vu.nl)