
In some
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
s, including
Unix
Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Linux
Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which i ...
, a pseudoterminal, pseudotty, or PTY is a pair of
pseudo-device
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow ...
endpoints (files) which establish asynchronous,
bidirectional
Bidirectional may refer to:
* Bidirectional, a roadway that carries traffic moving in opposite directions
* Bi-directional vehicle, a tram or train or any other vehicle that can be controlled from either end and can move forward or backward with e ...
communication (
IPC
IPC may refer to:
Computing
* Infrastructure protection centre or information security operations center
* Instructions per cycle or instructions per clock, an aspect of central-processing performance
* Inter-process communication, the sharin ...
) channel (with two ports) between two or more processes.
The ''master'' provides means by which a
terminal emulator
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 ter ...
process
A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic.
Things called a process include:
Business and management
*Business process, activities that produce a specific se ...
controls the slave. The ''slave'', emulates a hardware
text terminal
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 an ...
device.
PTY are similar to bidirectional pipes.
The ''master'' files are typically used by networking applications (e.g.
rlogin
The Berkeley r-commands are a suite of computer programs designed to enable users of one Unix system to log in or issue commands to another Unix computer via TCP/IP computer network. The r-commands were developed in 1982 by the Computer System ...
) and ''slave'' files are used by terminal-oriented programs such as shells (e.g.
bash) as a processes to read/write data back from/to ''master'' endpoint.
Common application of PTYs is in providing network login services.
Devpts is a
Linux Kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ...
virtual file system used to emulate PTYs connection.
Linux implementation is based on
System V
Unix System V (pronounced: "System Five") is one of the first commercial versions of the Unix operating system. It was originally developed by AT&T and first released in 1983. Four major versions of System V were released, numbered 1, 2, 3, an ...
-style terminals (commonly referred as UNIX 98 pseudoterminals) and provides
POSIX
The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming inte ...
and the
Single Unix Specification API in the form of a function since 1998.
Unix
command is typically used to get PTY file path connected to the current
standard input
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 ...
.
History
Pseudoterminals were present in the
DEC PDP-6
The PDP-6, short for Programmed Data Processor model 6, is a computer developed by Digital Equipment Corporation (DEC) during 1963 and first delivered in the summer of 1964.
It was an expansion of DEC's existing 18-bit systems to use a 36-bit ...
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 System (''Timesharing / Total Operating System-10'') is a discontinued operating system from Digital Equipment Corporation (DEC) for the PDP-10 (or DECsystem-10) mainframe computer family. Launched in 1967, TOPS-10 evolved from the earlier ...
on the
PDP-10
Digital Equipment Corporation (DEC)'s PDP-10, later marketed as the DECsystem-10, is a mainframe computer family manufactured beginning in 1966 and discontinued in 1983. 1970s models and beyond were marketed under the DECsystem-10 name, especi ...
. Other DEC operating systems also had PTYs, including
RSTS/E
RSTS () is a multi-user time-sharing operating system developed by Digital Equipment Corporation (DEC, now part of Hewlett-Packard) for the PDP-11 series of 16-bit minicomputers. The first version of RSTS (RSTS-11, Version 1) was implemented in ...
for the
PDP-11
The PDP-11 is a series of 16-bit minicomputers sold by Digital Equipment Corporation (DEC) from 1970 into the 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of all models were so ...
, as did the third-party
TENEX operating system for the PDP-10.
Implementations of Unix pseudo terminals date back to the modifications that RAND and BBN made to a 6th Edition in the late 1970s to support remote access over a network.
Modern Unix pseudoterminals 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
The Berkeley Software Distribution or Berkeley Standard Distribution (BSD) is a discontinued operating system based on Research Unix, developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Be ...
, with a rather cumbersome interface defined for use.
AT&T's
System V
Unix System V (pronounced: "System Five") is one of the first commercial versions of the Unix operating system. It was originally developed by AT&T and first released in 1983. Four major versions of System V were released, numbered 1, 2, 3, an ...
included support for pseudoterminals as a driver in their
STREAMS
A stream is a continuous body of surface water flowing within the bed and banks of a channel. Depending on its location or certain characteristics, a stream may be referred to by a variety of local or regional names. Long large streams ...
device model, along with the pseudoterminal multiplexer (). This later evolved to become the Unix98 style of PTYs.
Books
''
The Linux Programming Interface'' from 2010 contains an entire chapter (chapter 64 "Pseudoterminals" p1375–1399.) explaining pseudoterminals. Then there is another one, Chapter 62 "Terminals", dedicated to terminals.
The
Windows Console was extended to have a PTY interface called ConPTY in 2018.
Applications
The role of the terminal emulator process is:
* to interact with the user,
* to feed text input to the master pseudo-device for use by the shell (such as bash), which is connected to the slave pseudo-device,
* to read text output from the master pseudo-device and show it to the user.
The terminal emulator process must also handle terminal control commands, e.g., for resizing the screen. Widely used terminal emulator programs include ''
xterm
In computing, xterm is the standard terminal emulator for the X Window System. It allows users to run programs which require a command-line interface.
If no particular program is specified, xterm runs the user's shell. An X display can sho ...
'',
GNOME Terminal,
Konsole
Konsole is a free and open-source terminal emulator graphical application which is part of KDE Applications and ships with the KDE desktop environment. Konsole was originally written by Lars Doelle. It ls licensed under the GPL-2.0-or-later and ...
, and ''
Terminal (macOS)
This is a list of macOS built-in apps and system components.
Applications
App Store
The Mac App Store is macOS's digital distribution platform for macOS apps, created and maintained by Apple Inc. based on the iOS version, the platform was a ...
''. Remote login handlers such as
ssh and
telnet
Telnet is an application protocol used on the Internet or local area network to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection. User data is interspersed in-band with Telnet cont ...
servers play the same role but communicate with a remote user instead of a local one. Also consider programs such as
expect
Expect is an extension to the Tcl scripting language written by Don Libes. The program automates interactions with programs that expose a text terminal interface. Expect, originally written in 1990 for the Unix platform, has since become avai ...
.
Screen and
Tmux
tmux is an open-source terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same ti ...
are used to add a session context to a pseudoterminal, making for a much more robust and versatile solution. For example, each provides terminal persistence, allowing a user to disconnect from one computer and then connect later from another computer.
Variants
In the
BSD
The Berkeley Software Distribution or Berkeley Standard Distribution (BSD) is a discontinued operating system based on Research Unix, developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Be ...
PTY system, the slave device file, which generally has a name of the form
/dev/tty -za-e0-9a-f]
, supports all
system call
In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
s applicable to text terminal devices. Thus it supports
login session
In computing, a login session is the period of activity between a user logging in and logging out of a (multi-user) system.
On Unix and Unix-like operating systems, a login session takes one of two main forms:
* When a textual user interface is ...
s. The master device file, which generally has a name of the form
/dev/pty -za-e0-9a-f]
, is the endpoint for communication with the terminal emulator. With this naming scheme, there can be at most 256 tty pairs. Also, finding the first free pty master can be
Race condition, racy unless a locking scheme is adopted. For that reason, recent BSD operating systems, such as
FreeBSD
FreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular ...
, implement Unix98 PTYs.
BSD PTYs have been rendered obsolete by
Unix98 ptys whose naming system does not limit the number of pseudo-terminals and access to which occurs without danger of race conditions.
/dev/ptmx
is the "pseudo-terminal master multiplexer". Opening it returns a file descriptor of a master node and causes an associated slave node
/dev/pts/''N''
to be created.
See also
*
List of Unix commands
This is a list of Unix commands as specified by IEEE Std 1003.1-2008, which is part of the Single UNIX Specification (SUS). These commands can be found on Unix operating systems and most Unix-like operating systems.
List
See also
* List of G ...
References
{{Reflist
External links
Containers, pseudo TTYs, and backward compatibility LWN.net, June 1, 2016, by Neil Brown
Terminal emulators
Technical communication tools