ESSAYMarch 18, 2026·1 min read·[internals][systems][linux]
How PTYs actually work — a deep dive into pseudo-terminals
From driver to shell
Pseudo-terminals pair a master and slave device. Userland programs read and write the slave; the terminal emulator (or SSH server) holds the master.
Kernel interface
On Linux, openpty allocates both ends. The session leader gets a controlling tty on the slave; the line discipline handles ^C, ^Z, and echo.
Why it matters for tooling
If you spawn a child without a PTY, interactive programs may refuse to run or buffer differently. Tools that wrap shells need to allocate a PTY explicitly.
#!/usr/bin/env bash
set -euo pipefail
script -q -c "your-cli" /dev/null