pty(7)
๐ pty(7) โ pseudoterminal interfaces ๐
okay bestie, sit DOWN, because this is the page that explains how your terminal even exists, and it's lowkey the most iconic plumbing in all of Unix. it's from the Miscellaneous Information Manual (section 7, the "miscellaneous"/overview corner of the manual, iykyk) โ and no cap, this one is foundational.
โจ NAME โจ
pty โ pseudoterminal interfaces ๐ซถ
๐ DESCRIPTION ๐
A pseudoterminal (everyone abbreviates it to "pty", because who has the time) is a pair of virtual character devices that give you a bidirectional communication channel. ๐
One end of that channel is called the master; the other end is called the slave. That's the whole vibe: two ends, one convo.
The slave end is the overachiever โ it provides an interface that behaves exactly like a classical terminal. So if a process is out here expecting to be connected to a terminal, it can just open the slave end of a pseudoterminal and then get driven by a program that has opened the master end. ๐ธ
Here's the cute part:
- Anything written on the master end shows up to the process on the slave end as though it was input typed on a terminal. fr fr.
- So if you write the interrupt character (usually Ctrl+C โ yes, control-C, our beloved) to the master device, that causes an interrupt signal (
SIGINT) to be generated for the foreground process group that is connected to the slave. ๐ญ iconic. - And conversely: anything written to the slave end can be read by the process connected to the master end. reciprocity, we love to see it.
Data flow between master and slave is handled asynchronously, much like data flow with a physical terminal. Data written to the slave will be available at the master promptly, but may not be available immediately. Similarly, there may be a small processing delay between a write to the master and the effect being visible at the slave. (so don't @ it if there's a tiny lag, it's just living its life โจ)
Historically, two pseudoterminal APIs have evolved: BSD and System V. SUSv1 standardized a pseudoterminal API based on the System V API, and ๐ this ๐ API ๐ should be employed in all new programs that use pseudoterminals. periodt.
Linux provides both BSD-style and (standardized) System V-style pseudoterminals. System V-style terminals are commonly called UNIX 98 pseudoterminals on Linux systems.
๐จ since Linux 2.6.4, BSD-style pseudoterminals are considered deprecated: support can be disabled when building the kernel by disabling the CONFIG_LEGACY_PTYS option. (And starting with Linux 2.6.30, that option is disabled by default in the mainline kernel.) So: UNIX 98 pseudoterminals should be used in new applications. this is not a drill bestie ๐
๐ UNIX 98 pseudoterminals ๐
An unused UNIX 98 pseudoterminal master is opened by calling posix_openpt(3). (That function opens the master clone device, /dev/ptmx; see pts(4).) ๐
Then the whole ritual goes like this:
- After performing any program-specific initializations,
- change the ownership and permissions of the slave device using
grantpt(3), - unlock the slave using
unlockpt(3), - and then the corresponding slave device can be opened by passing the name returned by
ptsname(3)in a call toopen(2).
The Linux kernel imposes a limit on the number of available UNIX 98 pseudoterminals. Numbers time, bestie:
- Up to and including Linux 2.6.3, this limit is configured at kernel compilation time (
CONFIG_UNIX98_PTYS), and the permitted number of pseudoterminals can be up to 2048, with a default setting of 256. - Since Linux 2.6.4, the limit is dynamically adjustable via
/proc/sys/kernel/pty/max, and a corresponding file,/proc/sys/kernel/pty/nr, indicates how many pseudoterminals are currently in use. - For further details on these two files, see
proc(5). ๐
๐ฆ BSD pseudoterminals ๐ฆ
BSD-style pseudoterminals are provided as precreated pairs, with names of the form:
/dev/ptyXY
for the master, and:
/dev/ttyXY
for the slave โ where X is a letter from the 16-character set [p-za-e], and Y is a letter from the 16-character set [0-9a-f]. (The precise range of letters in these two sets varies across UNIX implementations โ so don't hardcode and expect, k?)
For example, /dev/ptyp1 and /dev/ttyp1 constitute a BSD pseudoterminal pair. ๐ซถ
A process finds an unused pseudoterminal pair by trying to open(2) each pseudoterminal master until an open succeeds. The corresponding pseudoterminal slave (substitute "tty" for "pty" in the name of the master) can then be opened. boom, that's the whole algorithm, no notes. ๐
๐ FILES ๐
/dev/ptmxโ UNIX 98 master clone device ๐/dev/pts/*โ UNIX 98 slave devices/dev/pty[p-za-e][0-9a-f]โ BSD master devices/dev/tty[p-za-e][0-9a-f]โ BSD slave devices
๐ NOTES ๐
Pseudoterminals are used by applications such as network login services (ssh(1), rlogin(1), telnet(1)), terminal emulators such as xterm(1), script(1), screen(1), tmux(1), unbuffer(1), and expect(1). so basically: everything you use all day, every day. main character energy, all of them. ๐
A description of the TIOCPKT ioctl(2), which controls packet mode operation, can be found in ioctl_tty(2). (go read it, iykyk ๐)
โ ๏ธ The BSDioctl(2)operationsTIOCSTOP,TIOCSTART,TIOCUCNTL, andTIOCREMOTEhave not been implemented under Linux. not me waiting for features that are never coming ๐
๐ SEE ALSO ๐
ioctl_tty(2), select(2), setsid(2), forkpty(3), openpty(3), termios(7), pts(4), tty(4)
and that's the whole page, bestie โ every flag, file, number, and signal, all facts intact, no cap. ๐
this was brought to you by Linux man-pages 6.20, dated 2026-07-02 โ pty(7), miscellaneous information manual gang, signing off ๐ซถโจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2005, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms