Skip to content
~1 min readinternalssystemslinux

How PTYs actually work — a deep dive into pseudo-terminals

From driver to shell

Save Latin
@savelatin

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
more posts

// prev/next sorted by date (newest first)

// post info
published2026-03-18
words96
read time1 min
categorydeep-dive
// related
projectterm-v0