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.)
321 field contains the following single bit flags that control output processing:
324 Perform output processing. This flag is the "main switch" on output
325 processing. All other flags are MINIX 3 specific.
332 sequence on output. Note that a key labeled "RETURN" or "ENTER" usually
335 In line oriented mode this is normally transformed into
340 is the normal UNIX line delimiter ('\en'). On output an
342 is transformed into the
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
353 into the number of spaces necessary to reach a column position that is a
359 (^D) characters. (Minix-vmd only.)
363 field contains the following single bit flags and bit field for basic
367 Ignore modem status lines.
370 Enable receiver. (The receiver is always enabled.)
373 Number of bits per byte.
381 that indicate that 5, 6, 7 or 8 bits are used.
384 Send two stop bits instead of one. Two stop bits are normally used at 110
388 Enable parity generation.
391 Generate odd parity if parity is generated, otherwise even parity.
394 Drop the modem control lines on the last close of the terminal line. (Not
399 field contains the following single bit flags that control various functions:
402 Enable echoing of input characters. Most input characters are echoed as
403 they are. Control characters are echoed as
407 is the letter used to say that the control character is
414 characters are echoed with their normal effect unless they are escaped by
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.
436 is not set then output an
440 character. (For hardcopy terminals it is best to unset
455 Canonical input. This enables line oriented input and erase and kill
459 Enable implementation defined input extensions.
462 Enable the signal characters
469 Disable the flushing of the input and output queues that is normally done if
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
504 as values used to indicate the given baud rates. The zero baud rate,
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
514 to get or set a speed, because the
518 fields may not be visible under other implementations. (The
526 symbols are MINIX 3 specific.)
527 .SS "Special characters"
530 array contains the special characters that can be modified. The array has
533 and is subscripted by the symbols
549 All these symbols are defined in
551 Some implementations may give the same values to the
559 subscripts respectively, and may ignore changes to
563 (Under MINIX 3 all special characters have their own
565 slot and can all be modified.)
566 .SS "Raw I/O Parameters"
571 parameters can be used to adjust a raw connection to bursty input.
573 represents a minimum number of bytes that must be received before a read
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:
580 .B "MIN > 0, TIME > 0"
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
586 the first character, so the read returns at least one byte.
588 .B "MIN > 0, TIME = 0"
589 Now the timer is disabled, and a reader blocks indefinitely until at least
591 characters are received.
593 .B "MIN = 0, TIME > 0"
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.)
599 .B "MIN = 0, TIME = 0"
600 The bytes currently available are returned. Zero is returned if no bytes
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
606 .SS "Session Leaders and Process Groups"
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
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
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
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.
635 For MINIX 3 a special write-only device
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
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
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
652 for input and output, and the remote login daemon uses the device
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
658 by the remote login daemon, undergoes input processing and appears on
660 as input to the login session. Output from the login session to
662 undergoes output processing, is read from
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.)
668 A pseudo terminal can be allocated by trying to open all the controlling
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.
675 If the tty side is eventually closed down then reads from the pty side will
676 return zero and writes return \-1 with
680 If the pty side is closed first then a
682 signal is sent to the session leader and further reads from the tty side
683 return zero and writes return \-1 with
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.)
692 The list below shows all devices that MINIX 3 and Minix-vmd have. Not all of
693 these devices are configured in by default, as indicated by the numbers
694 (i/j/k, l/m/n) that tell the minimum, default and maximum possible number of
695 these devices for MINIX 3 (i/j/k) and Minix-vmd (l/m/n).
701 Virtual consoles. (0/1/7, 0/1/7)
707 Serial lines. (0/2/2, 4/4/4)
709 .B /dev/tty[p-w][0-f]
710 Pseudo ttys. (0/0/64, 1/32/128)
712 .B /dev/pty[p-w][0-f]
713 Associated pseudo tty controllers.
721 A fair number of flags are not implemented under MINIX 3 (yet). Luckily they
722 are very limited utility and only apply to RS-232, not to the user interface.
724 Kees J. Bot (kjb@cs.vu.nl)