HOME

TheInfoList



OR:

In some
operating system An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
s, including
Unix-like A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
systems, a pseudoterminal, pseudotty, or PTY is a pair of pseudo-device endpoints (files) which establish an asynchronous, bidirectional communication ( IPC) channel (with two ports) between two or more processes. One pseudo-device in the pair, 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 term ...
or remote login server (e.g. a
Telnet Telnet (sometimes stylized TELNET) is a client-server application protocol that provides access to virtual terminals of remote systems on local area networks or the Internet. It is a protocol for bidirectional 8-bit communications. Its main ...
,
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 ...
, or
Secure Shell The Secure Shell Protocol (SSH Protocol) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution. SSH was designed for ...
server)
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 s ...
controls the slave. The other pseudo-device, the ''slave'', emulates a hardware
serial port A serial port is a serial communication Interface (computing), interface through which information transfers in or out sequentially one bit at a time. This is in contrast to a parallel port, which communicates multiple bits simultaneously in Pa ...
device, and is used by terminal-oriented programs such as shells (e.g. bash) as a processes to read/write data back from/to ''master'' endpoint. PTYs are similar to bidirectional pipes. Devpts is a
Linux kernel The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
virtual file system containing pseudoterminal devices. 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 application programming interfaces (APIs), along with comm ...
and the
Single Unix Specification The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
API in the form of a function since 1998.


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 da ...
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 "Mo ...
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, #Versions, Version 1) was implem ...
for the
PDP-11 The PDP–11 is a series of 16-bit minicomputers originally sold by Digital Equipment Corporation (DEC) from 1970 into the late 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of a ...
, 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.3BSD-Reno, 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 stream ...
device model, along with the pseudoterminal multiplexer (). This later evolved to become the Unix98 style of PTYs. Pseudoterminals have been standardized by the
Single UNIX Specification The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
(maintained by the
Austin Group The Austin Group or the Austin Common Standards Revision Group is a joint technical working group formed to develop and maintain a common revision of POSIX.1 and parts of the Single UNIX Specification. It is named after the location of the first ...
) since 2004 (Issue 6). From Issue 8 (2024) the description adopts
inclusive language Inclusive language is a language style that seeks to avoid expressions that its proponents perceive as expressing or implying ideas that are sexist, racist, or otherwise biased, prejudiced, or insulting to particular group(s) of people; and i ...
by replacing the word ''master'' with ''manager'' and the word ''slave'' with ''subsidiary'' (defect 1466).


Books

''
The Linux Programming Interface ''The Linux Programming Interface: A Linux and UNIX System Programming Handbook'' is a book written by Michael Kerrisk, which documents the Application programming interface, APIs of the Linux kernel and the GNU C Library (glibc). Book The boo ...
'' 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 Windows Console is a GUI application for running console applications in Windows. Windows Console is used for running text-based programs such as operating system shells (e.g. Command Prompt and PowerShell), utilities (e.g. Far Manager) an ...
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 , GNOME Terminal, Konsole, and Terminal. Remote login servers such as
Secure Shell The Secure Shell Protocol (SSH Protocol) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution. SSH was designed for ...
and
Telnet Telnet (sometimes stylized TELNET) is a client-server application protocol that provides access to virtual terminals of remote systems on local area networks or the Internet. It is a protocol for bidirectional 8-bit communications. Its main ...
servers play the same role but communicate with a remote user instead of a local one. 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 time ...
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 (BSD), also known as Berkeley Unix or BSD Unix, is a discontinued Unix operating system developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berkeley, beginni ...
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 (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, accessing a hard disk drive ...
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 introduce a
race condition A race condition or race hazard is the condition of an electronics, software, or other system where the system's substantive behavior is dependent on the sequence or timing of other uncontrollable events, leading to unexpected or inconsistent ...
unless a locking scheme is adopted. For that reason, recent BSD operating systems, such as
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
, 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 the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...


References

{{Reflist


External links


Containers, pseudo TTYs, and backward compatibility
LWN.net, June 1, 2016, by Neil Brown Terminal emulators Technical communication tools