How PTYs actually work — a deep dive into pseudo-terminals
From driver to shell
Save Latin
@savelatin
// contents (2)
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/nullmore posts
// prev/next sorted by date (newest first)
// post info
published2026-03-18
words96
read time1 min
categorydeep-dive
// related
projectterm-v0