Hasty Briefsbeta

Bilingual

The TTY Demystified (2008)

a day ago
  • #Terminal
  • #UNIX
  • #TTY
  • The TTY subsystem is crucial to Linux/UNIX design but often misunderstood, originating from historical teletypes and stock tickers.
  • TTY devices combine a UART driver, line discipline (like N_TTY for editing), and TTY driver for session management, allowing line editing and job control.
  • Modern systems use emulated terminals (like xterm) or pseudo terminals (ptys) instead of physical hardware, but legacy TTY functionality persists.
  • Process states include running, sleeping, stopped, and zombie, with job control managing foreground/background process groups via signals.
  • Key signals include SIGINT (^C), SIGTSTP (^Z), SIGTTIN/SIGTTOU (background job I/O), SIGWINCH (terminal resize), and SIGHUP (hangup).
  • TTY configuration can be modified via ioctl or stty, affecting baud rate, special characters (e.g., intr), canonical mode, and flow control (^S/^Q).
  • Flow control and blocking I/O regulate data flow between processes and terminals, with kernel buffers managing speed mismatches.
  • Session leaders (shells) coordinate jobs, TTY foreground settings, and handle signals like SIGCHLD for process state changes.
  • The article demystifies TTY internals, highlighting its role in terminal emulation, line disciplines, and userland tools like screen or ssh.
  • Feedback and corrections note nuances like raw vs. cooked mode, and discuss challenges in TTY relay over SSH or with complex terminal states.