What is a PTY?

A PTY, or pseudo-terminal, is a pair of linked virtual devices. A program runs on one end and sees a normal terminal, while another program controls the other end.

Updated

How a PTY works

A PTY has two ends. The master end is held by one program. The slave end acts like a physical terminal for another program. Data written to the master arrives at the slave as if typed on a terminal. Output from the slave can be read from the master.

Current Linux systems open the master through /dev/ptmx. Slave devices appear under /dev/pts/.

Why interactive programs need one

Interactive programs, such as shells, editors and REPLs, expect a terminal. Tools such as ssh, screen, tmux and expect use PTYs. So do terminal emulators such as xterm.

PTYs in sandboxes

Some sandbox SDKs start a PTY inside the sandbox. They stream its output through callbacks while the program runs. A web page can show that output in a terminal. xterm.js builds terminals in the browser. Visual Studio Code uses it for its integrated terminal.

What to check

  • Whether the SDK gives you a PTY, or only the output of a finished command.
  • Whether a session keeps its PTY after a disconnect.
  • Whether the SDK lets you resize the terminal.
Referenceman7.org

Related terms

All glossary terms

Related