Seventh Edition Unix terminal interface

Last updated

The Seventh Edition Unix terminal interface is the generalized abstraction, comprising both an application programming interface for programs and a set of behavioural expectations for users, of a terminal as historically available in Seventh Edition Unix. It has been largely superseded by the POSIX terminal interface.

Contents

Concepts and overview

The terminal interface provided by Seventh Edition Unix and UNIX/32V, and also presented by BSD version 4 as the old terminal driver, was a simple one, largely geared towards teletypewriters as terminals. Input was entered a line at a time, with the terminal driver in the operating system (and not the terminals themselves) providing simple line editing capabilities. A buffer was maintained by the kernel in which editing took place. Applications reading terminal input would receive the contents of the buffer only when the return key was pressed on the terminal to end line editing. The @ key sent from the terminal to the system would erase ("kill") the entire current contents of the editing buffer, and would be normally displayed as an '@' symbol followed by a newline sequence to move the print position to a fresh blank line. The # key sent from the terminal to the system would erase the last character from the end of the editing buffer, and would be normally displayed as an '#' symbol, which users would have to recognize as denoting a "rubout" of the preceding character (teletypewriters not being physically capable of erasing characters once they have been printed on the paper). [1] [2] [3] [4] [5]

From a programming point of view, a terminal device had transmit and receive baud rates, "erase" and "kill" characters (that performed line editing, as explained), "interrupt" and "quit" characters (generating signals to all of the processes for which the terminal was a controlling terminal), "start" and "stop" characters (used for software flow control), an "end of file" character (acting like a carriage return except discarded from the buffer by the read() system call and therefore potentially causing a zero-length result to be returned) and various mode flags determining whether local echo was emulated by the kernel's terminal driver, whether modem flow control was enabled, the lengths of various output delays, mapping for the carriage return character, and the three input modes. [6]

Input modes

The three input modes for terminals in Seventh Edition Unix were:

line mode (also called "cooked" mode)
In line mode the line discipline performs all line editing functions and recognizes the "interrupt" and "quit" control characters and transforms them into signals sent to processes. Applications programs reading from the terminal receive entire lines, after line editing has been completed by the user pressing return. [2] [7]
cbreak mode
cbreak mode is one of two character-at-a-time modes. (Stephen R. Bourne jokingly referred to it ( Bourne 1983 , p. 288) as a "half-cooked" and therefore "rare" mode.) The line discipline performs no line editing, and the control sequences for line editing functions are treated as normal character input. Applications programs reading from the terminal receive characters immediately, as soon as they are available in the input queue to be read. However, the "interrupt" and "quit" control characters, as well as modem flow control characters, are still handled specially and stripped from the input stream. [8] [9]
raw mode
raw mode is the other of the two character-at-a-time modes. The line discipline performs no line editing, and the control sequences for both line editing functions and the various special characters ("interrupt", "quit", and flow control) are treated as normal character input. Applications programs reading from the terminal receive characters immediately, and receive the entire character stream unaltered, just as it came from the terminal device itself. [10] [8] [9]

In the POSIX terminal interface, these modes have been superseded by a system of just two input modes: canonical and non-canonical. The handling of signal-generating special characters in the POSIX terminal interface is independent of input mode, and is separately controllable.

Controlling terminals

In Seventh Edition Unix there was no terminal job control and a process group was considered to be not what it is considered to be nowadays.

Each process in the system had either a single controlling terminal, or no controlling terminal at all. A process inherits its controlling terminal from its parent. A controlling terminal was acquired when a process with no controlling terminal open()s a terminal device file that isn't already the controlling terminal for some other process. All of the processes that had the same controlling terminal were part of a single process group. [11]

Application programming interface

The programmatic interface for querying and modifying all of these modes and control characters was the ioctl() system call. (This replaced the stty() and gtty() system calls of Sixth Edition Unix.) [12] [13] Although the "erase" and "kill" characters were modifiable from their defaults of # and @, for many years after Seventh Edition development inertia meant that they were the pre-set defaults in the terminal device drivers, and on many Unix systems, which only altered terminal device settings as part of the login process, in system login scripts that ran after the user had entered username and password, any mistakes at the login and password prompts had to be corrected using the historical editing key characters inherited from teletypewriter terminals. [4]

The symbolic constants, whose values were fixed and defined, and data structure definitions of the programmatic interface were defined in the sgtty.h system header. [8]

ioctl() operations

The ioctl() operations were as follows:

ioctl() operations for terminal devices
symbolstructure pointed to by third argumentdescription
TIOGETPsgttybquery terminal parameters into the data structure
TIOSETPsgttybset terminal parameters from the data structure, draining all pending output first and flushing queued input
TIOSETNsgttybset terminal parameters from the data structure, without waiting or draining
TIOCEXCLnoneswitch on "exclusive use" mode
TIOCNXCLnoneswitch off "exclusive use" mode
TIOCHPCLnoneswitch on "hangup at last close" mode
TIOCFLUSHnoneflush all output and input queues
TIOGETCtcharsquery terminal parameters into the data structure
TIOSETCtcharsset terminal parameters from the data structure

The sgttyb data structure

One data structure used by the terminal system calls is the sgttyb structure, whose C programming language definition is as follows: [14]

structsgttyb{charsg_ispeed;// Input speedcharsg_ospeed;// Output speedcharsg_erase;// Erase charactercharsg_kill;// Kill charactercharsg_flags;// Control flags};

Unlike the POSIX terminal interface, the Seventh Edition Unix terminal interface recorded input and output baud rates directly in the data structure. [15]

The input and output speeds in the sg_ispeed and sg_ospeed fields were those of the DEC DH-11, and were the numbers 0 to 15, represented by the symbolic constants (in ascending order) B0, B50, B75, B110,B134, B150, B200, B300, B600, B1200, B1800, B2400, B4800, B9600, EXTA, and EXTB, where the baud rate was as in the name (with the last two being "external A" and "external B"). Setting a baud rate of zero forced the terminal driver to hang up a modem (if the terminal was a modem device). [14]

The sg_erase and sg_kill fields were simply the character values of the "erase" and "kill" characters, respectively, defaulting to the (ASCII) values for '#' and '@' respectively. [14]

The sg_flags field specified various input and output control flags, as in the following table.

flags for the sg_flags field of the sgtty data structure [3]
symboloctal valuedescription
BSDELAY0100000delay when writing BS characters
BS00000000
BS10100000
VTDELAY0040000delay when writing VT and FF characters
FF00000000
FF10040000
CRDELAY0030000delay when writing CR characters
CR00000000
CR10010000
CR20020000
CR30030000
TBDELAY0006000delay when writing TAB characters
XTABS does not, technically, specify a delay, but rather causes tab characters to be converted to sequences of one or more space characters.
TAB00000000
TAB100002000
TAB20004000
XTABS0006000
NLDELAY0001400delay when writing LF characters
NL00000000
NL100000400
NL20001000
NL30001400
EVENP0000200even parity
ODDP0000100odd parity
RAW0000040"raw" mode
CRMOD0000020carriage return mapping mode (CR maps to LF on input and both CR and LF are turned into CR+LF on output)
ECHO0000010 local echo emulation by the terminal driver
LCASE0000004map uppercase to lower case on input
CBREAK0000002"cbreak" mode
TANDEM0000001enable modem flow control

The tchars data structure

One data structure used by the terminal system calls is the tchars structure, whose C programming language definition is as follows: [16]

structtchars{chart_intrc;// Interruptchart_quitc;// Quitchart_startc;// Startchart_stopc;// Stopchart_eofc;// End of Filechart_brkc;// Break (alternative to hardwired LF character with same effect)};

The values of these fields were the values of the various programmatically configurable special characters. A -1 value in any field disabled its recognition by the terminal driver. [16]

Related Research Articles

Teleprinter Device for transmitting messages in written form by electrical signals

A teleprinter is an electromechanical device that can be used to send and receive typed messages through various communications channels, in both point-to-point and point-to-multipoint configurations. Initially they were used in telegraphy, which developed in the late 1830s and 1840s as the first use of electrical engineering, though teleprinters were not used for telegraphy until 1887 at the earliest. The machines were adapted to provide a user interface to early mainframe computers and minicomputers, sending typed data to the computer and printing the response. Some models could also be used to create punched tape for data storage and to read back such tape for local printing or transmission.

Unix shell Command-line interpreter for Unix operating system

A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.

vi Keyboard-oriented text editor

vi is a screen-oriented text editor originally created for the Unix operating system. The portable subset of the behavior of vi and programs based on it, and the ex editor language supported within these programs, is described by the Single Unix Specification and POSIX.

Terminal emulator Program that emulates a video terminal

A terminal emulator, or terminal application, is a computer program that emulates a video terminal within some other display architecture. Though typically synonymous with a shell or text terminal, the term terminal covers all remote terminals, including graphical interfaces. A terminal emulator inside a graphical user interface is often called a terminal window.

Universal asynchronous receiver-transmitter Computer hardware device

A universal asynchronous receiver-transmitter is a computer hardware device for asynchronous serial communication in which the data format and transmission speeds are configurable. It sends data bits one by one, from the least significant to the most significant, framed by start and stop bits so that precise timing is handled by the communication channel. The electric signaling levels are handled by a driver circuit external to the UART. Two common signal levels are RS-232, a 12-volt system, and RS-485, a 5-volt system. Early teletypewriters used current loops.

In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console, but standard streams abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection or a pipeline. More generally, a child process inherits the standard streams of its parent process.

The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>. The functionality descends from a "portable I/O package" written by Mike Lesk at Bell Labs in the early 1970s, and officially became part of the Unix operating system in Version 7.

Computer terminal Computer input/output device for users

A computer terminal is an electronic or electromechanical hardware device that can be used for entering data into, and transcribing data from, a computer or a computing system. The teletype was an example of an early-day hard-copy terminal and predated the use of a computer screen by decades.

Text-based user interface Type of interface based on outputting to or controlling a text display

In computing, text-based user interfaces (TUI), is a retronym describing a type of user interface (UI) common as an early form of human–computer interaction, before the advent of graphical user interfaces (GUIs). Like GUIs, they may use the entire screen area and accept mouse and other inputs. They may also use color and often structure the display using special graphical characters such as ┌ and ╣, referred to in Unicode as the "box drawing" set. The modern context of use is usually a terminal emulator.

Pseudoterminal

In some operating systems, including Unix and Linux, a pseudoterminal, pseudotty, or PTY is a pair of pseudo-device endpoints (files) which establish asynchronous, bidirectional communication (IPC) channel between two or more processes. The master provides means by which a terminal emulator process controls the slave. The slave, emulates a hardware text terminal device. PTY are similar to bidirectional pipes.

A bell code is a device control code originally sent to ring a small electromechanical bell on tickers and other teleprinters and teletypewriters to alert operators at the other end of the line, often of an incoming message. Though tickers punched the bell codes into their tapes, printers generally do not print a character when the bell code is received. Bell codes are usually represented by the label "BEL". They have been used since 1870.

The seven standard Unix file types are regular, directory, symbolic link, FIFO special, block special, character special, and socket as defined by POSIX. Different OS-specific implementations allow more types than what POSIX requires. A file's type can be identified by the ls -l command, which displays the type in the first character of the file-system permissions field.

In computer networking, STREAMS is the native framework in Unix System V for implementing character device drivers, network protocols, and inter-process communication. In this framework, a stream is a chain of coroutines that pass messages between a program and a device driver. STREAMS originated in Version 8 Research Unix, as Streams.

In computing, ioctl is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; the effect of a call depends completely on the request code. Request codes are often device-specific. For instance, a CD-ROM device driver which can instruct a physical device to eject a disc would provide an ioctl request code to do so. Device-independent request codes are sometimes used to give userspace access to kernel functions which are only used by core system software or still under development.

A line discipline (LDISC) is a layer in the terminal subsystem in some Unix-like systems. The terminal subsystem consists of three layers: the upper layer to provide the character device interface, the lower hardware driver to communicate with the hardware or pseudo terminal, and the middle line discipline to implement behavior common to terminal devices.

In telecommunications, echo is the local display of data, either initially as it is locally sourced and sent, or finally as a copy of it is received back from a remote destination. Local echo is where the local sending equipment displays the outgoing sent data. Remote echo is where the display is a return copy of data as received remotely. Both are used together in a computed form of error detection to ensure that data received at the remote destination of a telecommunication are the same as data sent from the local source. When (two) modems communicate in echoplex mode the remote modem echoes whatever it receives from the local modem.

Command-line interface Type of computer interface based on entering text commands and viewing text output

A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and providing information to them as to what actions they are to perform. In some cases the invocation is conditional based on conditions established by the user or previous executables. Such access was first provided by computer terminals starting in the mid-1960s. This provided an interactive environment not available with punched cards or other input methods.

The POSIX terminal interface is the generalized abstraction, comprising both an Application Programming Interface for programs, and a set of behavioural expectations for users of a terminal, as defined by the POSIX standard and the Single Unix Specification. It is a historical development from the terminal interfaces of BSD version 4 and Seventh Edition Unix.

In computing and telecommunications, the capabilities of a terminal are various terminal features, above and beyond what is available from a pure teletypewriter, that host systems can make use of. They are (mainly) of control codes and escape codes that can be sent to or received from the terminal. The escape codes sent to the terminal perform various functions that a CRT terminal is capable of, but that a teletypewriter is not; such as moving the terminal's cursor to positions on the screen, clearing and scrolling all or parts of the screen, turning on and off attached printer devices, programming programmable function keys, changing display colours and attributes, and setting display title strings. The escape codes received from the terminal signify things such as function key, arrow key, and other special key keystrokes.

devpts

devpts is a virtual filesystem directory available in the Linux kernel since version 2.1.93. It is normally mounted at /dev/pts and contains solely devices files which represent slaves to the multiplexing master located at /dev/ptmx which is in turn is used to implement terminal emulators.

References

  1. Bourne 1983, p. 8.
  2. 1 2 Bourne 1983, p. 130131.
  3. 1 2 Bourne 1983, p. 287.
  4. 1 2 Christian 1988, p. 26.
  5. Leffler et al. 1989, p. 262.
  6. Bourne 1983, p. 132133.
  7. Leffler et al. 1989, p. 259260.
  8. 1 2 3 Bourne 1983, p. 288.
  9. 1 2 Leffler et al. 1989, p. 260.
  10. Bourne 1983, p. 132.
  11. Bourne 1983, p. 130.
  12. Bourne 1983, p. 133.
  13. Christian 1988, p. 393.
  14. 1 2 3 Bourne 1983, p. 286.
  15. Zlotnick 1991, p. 166.
  16. 1 2 Bourne 1983, p. 289.

Bibliography