TERMIOS(4) | Kernel Interfaces Manual | TERMIOS(4) |
In practice, applications seldom open these files; they are opened by special programs, such as getty(8) or rlogind(8), and become an application's standard input, output, and error files.
The grouping into process groups allows delivering of signals that stop or start the group as a whole, along with arbitrating which process group has access to the single controlling terminal. The grouping at a higher layer into sessions is to restrict the job control related signals and system calls to within processes resulting from a particular instance of a "login".
Typically, a session is created when a user logs in, and the login terminal is set up to be the controlling terminal; all processes spawned from that login shell are in the same session, and inherit the controlling terminal. A job control shell operating interactively (that is, reading commands from a terminal) normally groups related processes together by placing them into the same process group. A set of processes in the same process group is collectively referred to as a "job".
When the foreground process group of the terminal is the same as the process group of a particular job, that job is said to be in the foreground. When the process group of the terminal is different than the process group of a job (but is still the controlling terminal), that job is said to be in the background.
Normally the shell reads a command and starts the job that implements that command. If the command is to be started in the foreground (typical), it sets the process group of the terminal to the process group of the started job, waits for the job to complete, and then sets the process group of the terminal back to its own process group (it puts itself into the foreground).
If the job is to be started in the background (as denoted by the shell operator "&"), it never changes the process group of the terminal and doesn't wait for the job to complete (that is, it immediately attempts to read the next command).
If the job is started in the foreground, the user may type a character (usually ‘^Z
') which generates the terminal stop signal (SIGTSTP) and has the affect of stopping the entire job. The shell will notice that the job stopped (see wait(2)), and will resume running after placing itself in the foreground.
The shell also has commands for placing stopped jobs in the background, and for placing stopped or background jobs into the foreground.
The controlling terminal is inherited by a child process during a fork(2) function call. A process relinquishes its controlling terminal when it creates a new session with the setsid(2) function; other processes remaining in the old session that had this terminal as their controlling terminal continue to have it. A process does not relinquish its controlling terminal simply by closing all of its file descriptors associated with the controlling terminal if other processes continue to have it open.
When a controlling process terminates, the controlling terminal is disassociated from the current session, allowing it to be acquired by a new session leader. Subsequent access to the terminal by other processes in the earlier session will be denied, with attempts to access the terminal treated as if modem disconnect had been sensed.
If a process is in the foreground process group of its controlling terminal, write operations are allowed. Attempts by a process in a background process group to write to its controlling terminal will cause the process group to be sent a SIGTTOU signal unless one of the following special cases apply: If TOSTOP is not set, or if TOSTOP is set and the process is ignoring or blocking the SIGTTOU signal, the process is allowed to write to the terminal and the SIGTTOU signal is not sent. If TOSTOP is set, and the process group of the writing process is orphaned, and the writing process is not ignoring or blocking SIGTTOU, the write(2) returns -1 with errno set to EIO and no signal is sent.
Certain calls that set terminal parameters are treated in the same fashion as write, except that TOSTOP is ignored; that is, the effect is identical to that of terminal writes when TOSTOP is set.
Two general kinds of input processing are available, determined by whether the terminal device file is in canonical mode or noncanonical mode. Additionally, input characters are processed according to the c_iflag and c_lflag fields. Such processing can include echoing, which in general means transmitting input characters immediately back to the terminal when they are received from the terminal. This is useful for terminals that can operate in full-duplex mode.
The manner in which data is provided to a process reading from a terminal device file is dependent on whether the terminal device file is in canonical or noncanonical mode.
Another dependency is whether the O_NONBLOCK flag is set by open(2) or fcntl(2). If the O_NONBLOCK flag is clear, then the read request is blocked until data is available or a signal has been received. If the O_NONBLOCK flag is set, then the read request is completed, without blocking, in one of three ways:
When data is available depends on whether the input processing mode is canonical or noncanonical.
\n
' character, an end-of-file (EOF) character, or an end-of-line (EOL) character. See the Special Characters section for more information on EOF and EOL. This means that a read request will not return until an entire line has been typed, or a signal has been received. Also, no matter how many bytes are requested in the read call, at most one line is returned. It is not, however, necessary to read a whole line at once; any number of bytes, even one, may be requested in a read without losing information.{MAX_CANON} is a limit on the number of bytes in a line. The behavior of the system when this limit is exceeded is the same as when the input queue limit {MAX_INPUT}, is exceeded.
Erase and kill processing occur when either of two special characters, the ERASE and KILL characters (see the Special Characters section), is received. This processing affects data in the input queue that has not yet been delimited by a newline NL, EOF, or EOL character. This un-delimited data makes up the current line. The ERASE character deletes the last character in the current line, if there is any. The KILL character deletes all data in the current line, if there is any. The ERASE and KILL characters have no effect if there is no data in the current line. The ERASE and KILL characters themselves are not placed in the input queue.
VMIN represents the minimum number of bytes that should be received when the read(2) system call successfully returns. VTIME is a timer of 0.1 second granularity that is used to time out bursty and short term data transmissions. If VMIN is greater than {MAX_INPUT}, the response to the request is undefined. The four possible values for VMIN and VTIME and their interactions are described below.
\n
'.\r
', as denoted in the C Standard {2}. When ICANON and ICRNL are set and IGNCR is not set, this character is translated into a NL, and has the same effect as a NL character.The following special characters are extensions defined by this system and are not a part of IEEE Std 1003.1 (“POSIX.1”) termios.
The NL and CR characters cannot be changed. The values for all the remaining characters can be set and are described later in the document under Special Control Characters.
Special character functions associated with changeable special control characters can be disabled individually by setting their value to {_POSIX_VDISABLE}; see Special Control Characters.
If two or more special characters have the same value, the function performed when that character is received is undefined.
In the context of asynchronous serial data transmission, a break condition is defined as a sequence of zero-valued bits that continues for more than the time to send one byte. The entire sequence of zero-valued bits is interpreted as a single break condition, even if it continues for a time equivalent to more than one byte. In contexts other than asynchronous serial data transmission the definition of a break condition is implementation defined.
If IGNBRK is set, a break condition detected on input is ignored, that is, not put on the input queue and therefore not read by any process. If IGNBRK is not set and BRKINT is set, the break condition flushes the input and output queues and if the terminal is the controlling terminal of a foreground process group, the break condition generates a single SIGINT signal to that foreground process group. If neither IGNBRK nor BRKINT is set, a break condition is read as a single ‘\0
', or if PARMRK is set, as ‘\377
', ‘\0
', ‘\0
'.
If IGNPAR is set, a byte with a framing or parity error (other than break) is ignored.
If PARMRK is set, and IGNPAR is not set, a byte with a framing or parity error (other than break) is given to the application as the three-character sequence ‘\377
', ‘\0
', X, where ‘\377
', ‘\0
' is a two-character flag preceding each sequence and X is the data of the character received in error. To avoid ambiguity in this case, if ISTRIP is not set, a valid character of ‘\377
' is given to the application as ‘\377
', ‘\377
'. If neither PARMRK nor IGNPAR is set, a framing or parity error (other than break) is given to the application as a single character ‘\0
'.
If INPCK is set, input parity checking is enabled. If INPCK is not set, input parity checking is disabled, allowing output parity generation without input parity errors. Note that whether input parity checking is enabled or disabled is independent of whether parity detection is enabled or disabled (see Control Modes). If parity detection is enabled but input parity checking is disabled, the hardware to which the terminal is connected recognizes the parity bit, but the terminal special file does not check whether this bit is set correctly or not.
If ISTRIP is set, valid input bytes are first stripped to seven bits, otherwise all eight bits are processed.
If INLCR is set, a received NL character is translated into a CR character. If IGNCR is set, a received CR character is ignored (not read). If IGNCR is not set and ICRNL is set, a received CR character is translated into a NL character.
If IXON is set, start/stop output control is enabled. A received STOP character suspends output and a received START character restarts output. If IXANY is also set, then any character may restart output. When IXON is set, START and STOP characters are not read, but merely perform flow control functions. When IXON is not set, the START and STOP characters are read.
If IXOFF is set, start/stop input control is enabled. The system shall transmit one or more STOP characters, which are intended to cause the terminal device to stop transmitting data, as needed to prevent the input queue from overflowing and causing the undefined behavior described in Input Processing and Reading Data, and shall transmit one or more START characters, which are intended to cause the terminal device to resume transmitting data, as soon as the device can continue transmitting data without risk of overflowing the input queue. The precise conditions under which STOP and START characters are transmitted are implementation defined.
If IMAXBEL is set and the input queue is full, subsequent input shall cause an ASCII BEL character to be transmitted to the output queue.
The initial input control value after open(2) is implementation defined.
If OPOST is set, the remaining flag masks are interpreted as follows; otherwise characters are transmitted without change.
If ONLCR is set, newlines are translated to carriage return, linefeeds.
If OCRNL is set, carriage returns are translated to newlines.
If OXTABS is set, tabs are expanded to the appropriate number of spaces (assuming 8 column tab stops).
If ONOEOT is set, ASCII EOT's are discarded on output.
If ONOCR is set, no CR character is transmitted when at column 0 (first position).
If ONLRET is set, the NL character is assumed to do the carriage-return function; the column pointer will be set to 0.
The CSIZE bits specify the byte size in bits for both transmission and reception. The c_cflag is masked with CSIZE and compared with the values CS5, CS6, CS7, or CS8. This size does not include the parity bit, if any. If CSTOPB is set, two stop bits are used, otherwise one stop bit. For example, at 110 baud, two stop bits are normally used.
If CREAD is set, the receiver is enabled. Otherwise, no character is received. Not all hardware supports this bit. In fact, this flag is pretty silly and if it were not part of the termios specification it would be omitted.
If PARENB is set, parity generation and detection are enabled and a parity bit is added to each character. If parity is enabled, PARODD specifies odd parity if set, otherwise even parity is used.
If HUPCL is set, the modem control lines for the port are lowered when the last process with the port open closes the port or the process terminates. The modem connection is broken.
If CLOCAL is set, a connection does not depend on the state of the modem status lines. If CLOCAL is clear, the modem status lines are monitored.
Under normal circumstances, a call to the open(2) function waits for the modem connection to complete. However, if the O_NONBLOCK flag is set or if CLOCAL has been set, the open(2) function returns immediately without waiting for the connection.
If the tty(4) TIOCFLAG_CLOCAL flag has been set on the port then the CLOCAL flag will automatically be set on every open.
The CCTS_OFLOW and CRTS_IFLOW flags are currently unused. Only CRTSCTS, which has the combined effect, is implemented. Note that CRTSCTS support is hardware and driver dependent. Check the specific port driver manual page to see if hardware flow control is supported on the port you are using.
If the tty(4) TIOCFLAG_CRTSCTS flag has been set on the port then the CRTSCTS flag will automatically be set on every open.
If MDMBUF is set then output flow control is controlled by the state of Carrier Detect.
If the tty(4) TIOCFLAG_MDMBUF flag has been set on the port then the MDMBUF flag will automatically be set on every open.
If the object for which the control modes are set is not an asynchronous serial connection, some of the modes may be ignored; for example, if an attempt is made to set the baud rate on a network connection to a terminal on another host, the baud rate may or may not be set on the connection between that terminal and the machine it is directly connected to.
If ECHO is set, input characters are echoed back to the terminal. If ECHO is not set, input characters are not echoed.
If ECHOE and ICANON are set, the ERASE character causes the terminal to erase the last character in the current line from the display, if possible. If there is no character to erase, an implementation may echo an indication that this was the case or do nothing.
If ECHOK and ICANON are set, the KILL character causes the current line to be discarded and the system echoes the ‘\n
' character after the KILL character.
If ECHOKE and ICANON are set, the KILL character causes the current line to be discarded and the system causes the terminal to erase the line from the display.
If ECHOPRT and ICANON are set, the system assumes that the display is a printing device and prints a backslash and the erased characters when processing ERASE characters, followed by a forward slash.
If ECHOCTL is set, the system echoes control characters in a visible fashion using a caret followed by the control character.
If ALTWERASE is set, the system uses an alternative algorithm for determining what constitutes a word when processing WERASE characters (see WERASE).
If ECHONL and ICANON are set, the ‘\n
' character echoes even if ECHO is not set.
If ICANON is set, canonical processing is enabled. This enables the erase and kill edit functions, and the assembly of input characters into lines delimited by NL, EOF, and EOL, as described in Canonical Mode Input Processing.
If ICANON is not set, read requests are satisfied directly from the input queue. A read is not satisfied until at least VMIN bytes have been received or the timeout value VTIME expired between bytes. The time value represents tenths of seconds. See Noncanonical Mode Input Processing for more details.
If ISIG is set, each input character is checked against the special control characters INTR, QUIT, and SUSP (job control only). If an input character matches one of these control characters, the function associated with that character is performed. If ISIG is not set, no checking is done. Thus these special input functions are possible only if ISIG is set.
If IEXTEN is set, implementation-defined functions are recognized from the input data. How IEXTEN being set interacts with ICANON, ISIG, IXON, or IXOFF is implementation defined. If IEXTEN is not set, then implementation-defined functions are not recognized, and the corresponding input characters are not processed as described for ICANON, ISIG, IXON, and IXOFF.
If NOFLSH is set, the normal flush of the input and output queues associated with the INTR, QUIT, and SUSP characters are not be done.
If TOSTOP is set, the signal SIGTTOU is sent to the process group of a process that tries to write to its controlling terminal if it is not in the foreground process group for that terminal. This signal, by default, stops the members of the process group. Otherwise, the output generated by that process is output to the current output stream. Processes that are blocking or ignoring SIGTTOU signals are excepted and allowed to produce output and the SIGTTOU signal is not sent.
If NOKERNINFO is set, the kernel does not produce a status message when processing STATUS characters (see STATUS).
Index Name | Special Character | Default Value |
VEOF | EOF | ^D |
VEOL | EOL | _POSIX_VDISABLE |
VEOL2 | EOL2 | _POSIX_VDISABLE |
VERASE | ERASE |
^? ‘\177 ' |
VWERASE | WERASE | ^W |
VKILL | KILL | ^U |
VREPRINT | REPRINT | ^R |
VINTR | INTR | ^C |
VQUIT | QUIT |
^\\ ‘\34 ' |
VSUSP | SUSP | ^Z |
VDSUSP | DSUSP | ^Y |
VSTART | START | ^Q |
VSTOP | STOP | ^S |
VLNEXT | LNEXT | ^V |
VDISCARD | DISCARD | ^O |
VMIN | --- | 1 |
VTIME | --- | 0 |
VSTATUS | STATUS | ^T |
If the value of one of the changeable special control characters (see Special Characters) is {_POSIX_VDISABLE}, that function is disabled; that is, no input data is recognized as the disabled special character. If ICANON is not set, the value of {_POSIX_VDISABLE} has no special meaning for the VMIN and VTIME entries of the c_cc array.
The initial values of the flags and control characters after open(2) is set according to the values in the header <sys/ttydefaults.h>.
October 7, 2006 | NetBSD 6.1 |