Section 10.1. Terminal-Processing Modes

   


10.1. Terminal-Processing Modes

FreeBSD supports several modes of terminal processing. Much of the time, keyboard input is in canonical mode (also commonly referred to as cooked mode or line mode), in which input characters are echoed by the operating system as they are typed by the user but are buffered internally until a newline character is received. Only after the receipt of a newline character is the entire line made available to the shell or other process reading from the keyboard. If the process attempts to read from the keyboard before a complete line is ready, the process will sleep until a newline character is received, regardless of a partial line already having been received. The common case where a carriage return behaves like a newline character and causes the line to be made available to the waiting process is implemented by the operating system and is configurable by the user or process. In canonical mode, the user may correct typing errors, deleting the most recently typed character with the erase character, deleting the most recent word with the word-erase character, or deleting the entire current line with the kill character. Other special characters generate signals sent to processes associated with the keyboard; these signals may abort processing or may suspend it. Additional characters start and stop output, flush output, or prevent special interpretation of the succeeding character. The user can type several lines of input, up to an implementation-defined limit, without waiting for input to be read and then removed from the input queue. The user can specify the special processing characters or can selectively disable them.

Screen editors and programs that communicate with other computers generally run in noncanonical mode (also commonly referred to as raw mode or character-at-a-time mode). In this mode, the system makes each typed character available to be read as input as soon as that character is received. All special-character input processing is disabled, no erase or other line-editing processing is done, and all characters are passed to the program reading from the keyboard.

It is possible to configure keyboard input in thousands of combinations between these two extremes. For example, a screen editor that wanted to receive user interrupts asynchronously might enable the special characters that generate signals but otherwise run in noncanonical mode.

In addition to processing input characters, the terminal interface must do certain processing on output. Most of the time, this processing is simple: Newline characters are converted to a carriage return plus a line feed. In addition to doing character processing, the terminal output routines must manage flow control, both with the user (using stop and start characters) and with the process. Because users absorb output slowly in comparison with computer peripherals, a program writing to a terminal may produce output much faster than that output can be handled by the user. When a process has filled the terminal output queue, it will be put to sleep; it will be restarted when enough output has drained.


   
 


The Design and Implementation of the FreeBSD Operating System
The Design and Implementation of the FreeBSD Operating System
ISBN: 0201702452
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net