Pseudo terminal
Encyclopedia
In some operating systems
, including Unix
, a pseudo terminal is a pseudo-device pair that provides a text terminal interface without an associated device, such as a virtual console, computer terminal
or serial port
. Instead, a process assumes the role of the underlying hardware for the pseudo terminal session.
s of any text terminal. Thus it has the understanding of a login
session and session leader process (which is typically the shell program).
The master device file, which generally has a nomenclature of
With the typical [p-za-e] naming, there can be at most 256 tty pairs. Also, finding the first free pty master is not entirely race-free. For that reason, modern BSD operating systems, such as FreeBSD
, implement Unix98 PTYs.
to the master file is returned to the calling process. Library functions usually also exist that open the first available master device file and initialize privileges of the corresponding slave device (e.g. openpty(3) on BSD Unix systems).
For example, if the first master device file available is /dev/ptypa, most library functions will return a descriptor for the master (/dev/ptypa) along with a descriptor for the corresponding slave (/dev/ttypa), and establish the permissions of the slave device file in some predefined fashion.
It is generally not allowed to open a pseudo terminal master device that is currently open elsewhere.
Some systems, notably System V derived ones, include a multiplexer
device (usually /dev/ptmx) that, when opened, will return a descriptor associated to the first available master device.
New code should always use standardized programming interfaces like posix_openpt(2) to allocate pseudo-terminals.
and similar terminal emulator
s in the X Window System
and other window systems (such as the Terminal
application in Mac OS X
), in which the terminal emulator process is associated with the master device and the shell is associated with the slave. Any terminal operations performed by the shell in a terminal emulator session are received and handled by the terminal emulator process itself (such as terminal resizing or terminal resets). The terminal emulator process receives input from the keyboard and mouse using windowing events, and is thus able to transmit these characters to the shell, giving the shell the appearance of the terminal emulator being an underlying hardware object.
Other important applications include remote login handlers such as ssh
and telnet
servers, which serve as the master for a corresponding shell, bridged by a pseudo terminal.
Another key application is expect
, which allows the automation of arbitrary terminal-bound subprocesses by using a pseudo-terminal to conceal the fact that the subprocess is being controlled by a program and not a user (many programs change their observed behavior otherwise, often because of varying default buffering semantics).
Screen
or Tmux
are used to add a session context to a pseudo terminal, making for a much more robust and versatile solution. For example, it provides terminal persistence allowing to disconnect from one computer and connect later on from another computer on the net.
PDP-6
Timesharing Monitor at least as early as 1967, and were used to implement batch processing. They are described in the documentation for the succeeding TOPS-10
on the PDP-10
. Other DEC operating systems also had PTYs, including RSTS/E
for the PDP-11
, as did the third-party TENEX operating system for the PDP-10.
Unix pseudo terminals originated in 1983 during the development of Eighth Edition Unix
and were based on a similar feature in TENEX. They were part of the 4.2 release of BSD. AT&T's System V included support for pseudo terminals as a driver in their STREAMS device model, along with the pseudo terminal multiplexer.
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...
, including Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
, a pseudo terminal is a pseudo-device pair that provides a text terminal interface without an associated device, such as a virtual console, computer terminal
Computer terminal
A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...
or serial port
Serial port
In computing, a serial port is a serial communication physical interface through which information transfers in or out one bit at a time...
. Instead, a process assumes the role of the underlying hardware for the pseudo terminal session.
BSD PTYs
The slave device file, which generally has a nomenclature of/dev/tty[p-za-e][0-9a-f]
, has the appearance and supported system callSystem call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...
s of any text terminal. Thus it has the understanding of a login
Logging (computer security)
In computer security, a login or logon is the process by which individual access to a computer system is controlled by identifying and authentifying the user referring to credentials presented by the user.A user can log in to a system to obtain access and can then log out or log off In computer...
session and session leader process (which is typically the shell program).
The master device file, which generally has a nomenclature of
/dev/pty[p-za-e][0-9a-f]
, is the endpoint for communication with the terminal emulator. It receives the control requests and information from the other party over this interface and responds accordingly.With the typical [p-za-e] naming, there can be at most 256 tty pairs. Also, finding the first free pty master is not entirely race-free. For that reason, modern BSD operating systems, such as FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...
, implement Unix98 PTYs.
Unix98 PTYs
BSD PTYs have been made obsolete by Unix98 ptys, which allow race-free access and their number is not limited by nomenclature, only by implementation./dev/ptmx
is the "pseudo-terminal master multiplexer" which, when opened, causes a slave node /dev/pts/N
node to appear (with N being an integer). ptsname(3) can be used to obtain the name of the slave node. The file descriptor, obtained by opening ptmx plus the slave node, form the tty pair.Creating pseudo terminals
Pseudo terminals can be created using ordinary system calls to open an available master device file, in which a file descriptorFile descriptor
In computer programming, a file descriptor is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems...
to the master file is returned to the calling process. Library functions usually also exist that open the first available master device file and initialize privileges of the corresponding slave device (e.g. openpty(3) on BSD Unix systems).
For example, if the first master device file available is /dev/ptypa, most library functions will return a descriptor for the master (/dev/ptypa) along with a descriptor for the corresponding slave (/dev/ttypa), and establish the permissions of the slave device file in some predefined fashion.
It is generally not allowed to open a pseudo terminal master device that is currently open elsewhere.
Some systems, notably System V derived ones, include a multiplexer
Multiplexer
In electronics, a multiplexer is a device that selects one of several analog or digital input signals and forwards the selected input into a single line. A multiplexer of 2n inputs has n select lines, which are used to select which input line to send to the output...
device (usually /dev/ptmx) that, when opened, will return a descriptor associated to the first available master device.
New code should always use standardized programming interfaces like posix_openpt(2) to allocate pseudo-terminals.
Applications
Important applications of pseudo terminals include xtermXterm
In computing, xterm is the standard terminal emulator for the X Window System. A user can have many different invocations of xterm running at once on the same display, each of which provides independent input/output for the process running in it .xterm originated prior to the X Window System...
and similar terminal emulator
Terminal emulator
A terminal emulator, terminal application, term, or tty for short, is a program that emulates a video terminal within some other display architecture....
s in the X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...
and other window systems (such as the Terminal
Terminal (application)
Terminal is a terminal emulator included in Apple's Mac OS X operating system. It originated in Mac OS X's predecessors, NeXTSTEP and OPENSTEP, and allows the user to interact with the computer through a command line interface. By default it provides a bash shell, which allows the OS X user to...
application in Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
), in which the terminal emulator process is associated with the master device and the shell is associated with the slave. Any terminal operations performed by the shell in a terminal emulator session are received and handled by the terminal emulator process itself (such as terminal resizing or terminal resets). The terminal emulator process receives input from the keyboard and mouse using windowing events, and is thus able to transmit these characters to the shell, giving the shell the appearance of the terminal emulator being an underlying hardware object.
Other important applications include remote login handlers such as ssh
Secure Shell
Secure Shell is a network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers that it connects via a secure channel over an insecure network: a server and a client...
and telnet
TELNET
Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communications facility using a virtual terminal connection...
servers, which serve as the master for a corresponding shell, bridged by a pseudo terminal.
Another key application is expect
Expect
Expect is a Unix automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. It uses Unix pseudo terminals to wrap up subprocesses transparently, allowing the...
, which allows the automation of arbitrary terminal-bound subprocesses by using a pseudo-terminal to conceal the fact that the subprocess is being controlled by a program and not a user (many programs change their observed behavior otherwise, often because of varying default buffering semantics).
Screen
GNU Screen
GNU Screen is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session...
or Tmux
Tmux
Tmux is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session...
are used to add a session context to a pseudo terminal, making for a much more robust and versatile solution. For example, it provides terminal persistence allowing to disconnect from one computer and connect later on from another computer on the net.
Origins
Pseudo terminals were present in the DECDigital Equipment Corporation
Digital Equipment Corporation was a major American company in the computer industry and a leading vendor of computer systems, software and peripherals from the 1960s to the 1990s...
PDP-6
PDP-6
The PDP-6 was a computer model developed by Digital Equipment Corporation in 1963. It was influential primarily as the prototype for the later PDP-10; the instruction sets of the two machines are almost identical.The PDP-6 was DEC's first "big" machine...
Timesharing Monitor at least as early as 1967, and were used to implement batch processing. They are described in the documentation for the succeeding TOPS-10
TOPS-10
The TOPS-10 System was a computer operating system from Digital Equipment Corporation for the PDP-10 mainframe computer launched in 1967...
on the PDP-10
PDP-10
The PDP-10 was a mainframe computer family manufactured by Digital Equipment Corporation from the late 1960s on; the name stands for "Programmed Data Processor model 10". The first model was delivered in 1966...
. Other DEC operating systems also had PTYs, including RSTS/E
RSTS/E
RSTS is a multi-user time-sharing operating system, developed by Digital Equipment Corporation , for the PDP-11 series of 16-bit minicomputers. The first version of RSTS was implemented in 1970 by DEC software engineers that developed the TSS-8 time-sharing operating system for the PDP-8...
for the PDP-11
PDP-11
The PDP-11 was a series of 16-bit minicomputers sold by Digital Equipment Corporation from 1970 into the 1990s, one of a succession of products in the PDP series. The PDP-11 replaced the PDP-8 in many real-time applications, although both product lines lived in parallel for more than 10 years...
, as did the third-party TENEX operating system for the PDP-10.
Unix pseudo terminals originated in 1983 during the development of Eighth Edition Unix
Version 8 Unix
Eighth Edition Unix, also known as Version 8 Unix or V8, was a version of the Research Unix operating system developed and used internally at Bell Labs and a select number of universities. It was "released" in February 1985, ran on VAX hardware, and was a variant of 4.1cBSD with some System V.1 ...
and were based on a similar feature in TENEX. They were part of the 4.2 release of BSD. AT&T's System V included support for pseudo terminals as a driver in their STREAMS device model, along with the pseudo terminal multiplexer.