From Wikipedia, the free encyclopedia
(Redirected from Pseudo terminal)
Pseudoterminals as they are used by script unix command that records user's input for replaying it later.

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 (with two ports) between two or more processes.[1][2][3] The master provides means by which a terminal emulator process controls the slave. The slave emulates a hardware text terminal device.[1] PTY are similar to bidirectional pipes.[4]

The master files are typically used by networking applications (e.g. rlogin) 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.[1] Common application of PTYs is in providing network login services.[3]

Devpts is a Linux Kernel virtual file system used to emulate PTYs connection.

Linux implementation is based on System V-style terminals (commonly referred as UNIX 98 pseudoterminals)[5] and provides POSIX and the Single Unix Specification API in the form of a posix_openpt() function since 1998.[6]

Unix tty command is typically used to get PTY file path connected to the current standard input.


Pseudoterminals were present in the DEC 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.[7] 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.

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.[8] Modern Unix pseudoterminals originated in 1983 during the development of Eighth Edition Unix and were based on a similar feature in TENEX.[9] They were part of the 4.2 release of BSD, with a rather cumbersome openpty() interface defined for use.[10]

AT&T's System V included support for pseudoterminals as a driver in their STREAMS device model, along with the pseudoterminal multiplexer (/dev/ptmx). This later evolved to become the Unix98 style of PTYs.


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.[11]


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, GNOME Terminal, Konsole, and Terminal (macOS). Remote login handlers such as ssh and telnet servers play the same role but communicate with a remote user instead of a local one. Also consider programs such as expect.

Screen and Tmux 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.


In the BSD PTY system, the slave device file, which generally has a name of the form /dev/tty[p-za-e][0-9a-f], supports all system calls applicable to text terminal devices. Thus it supports login sessions. The master device file, which generally has a name of the form /dev/pty[p-za-e][0-9a-f], is the endpoint for communication with the terminal emulator. With this [p-za-e] naming scheme, there can be at most 256 tty pairs. Also, finding the first free pty master can be racy unless a locking scheme is adopted. For that reason, recent BSD operating systems, such as FreeBSD, implement Unix98 PTYs.[12]

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.[13]

See also[edit]


  1. ^ a b c "Pseudoterminal files". 2016-02-12. Retrieved 2021-09-30.
  2. ^ "Chapter 64: Pseudoterminals - The Linux Programming Interface [Book]". Retrieved 2021-09-30.
  3. ^ a b Kerrisk, Michael (2010). The Linux programming interface : a Linux and UNIX system programming handbook. San Francisco: No Starch Press. ISBN 978-1-59327-291-3. OCLC 728672600.
  4. ^ Kerrisk, Michael (2010). The Linux programming interface : a Linux and UNIX system programming handbook. San Francisco: No Starch Press. p. 1388. ISBN 978-1-59327-291-3. OCLC 728672600.
  5. ^ "pty(7) - Linux manual page". Retrieved 2021-09-30.
  6. ^ posix_openpt – System Interfaces Reference, The Single UNIX Specification, Version 4 from The Open Group
  7. ^ PDP-10 Timesharing Monitors Programmer's Reference Manual section 5.10
  8. ^ ``PTY Driver for SRI-NOSC Net UNIX lines 15-31
  9. ^ Ritchie, D. M. "A stream input-output system". AT&T Bell Laboratories Technical Journal. 63 (8): 1897–1910. CiteSeerX doi:10.1002/j.1538-7305.1984.tb00071.x. S2CID 33497669.
  10. ^ openpty(3) – FreeBSD Library Functions Manual
  11. ^ "Introducing the Windows Pseudo Console (ConPTY)". Windows Command Line DevBolgs. 3 August 2018.
  12. ^ pty(4) – FreeBSD Kernel Interfaces Manual
  13. ^ pts(4) – Linux Programmer's Manual – Special Files

External links[edit]