PTY(4)

πŸ’– PTY(4) πŸ’–

okay bestie, gather round β€” this is the manual page for pty, section 4 of the Kernel Interfaces Manual. it's giving "vintage but still showing up to the party" energy. let's get into it 🫢


✨ NAME ✨

pty β€” the old-style compatibility pseudo-terminal driver. yes, compatibility, as in "we keep it around for the elders." iconic behavior honestly.


🌸 SYNOPSIS 🌸

device pty

that's it. that's the whole vibe. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so the pty driver is basically the nostalgia corner of pseudo-terminals. it supports the traditional BSD naming scheme that everybody used for accessing pseudo-terminals before pts(4) came in and took over. and like β€” that traditional naming is still what Linux uses, so it never fully left the group chat. no cap.

here's the tea: when the device /dev/ptyXX gets opened, a new terminal shall be created using the pts(4) driver. and then a device node for that terminal gets created too, named /dev/ttyXX. ✨ automatic. no notes.

the pty driver also hands you a cloning System V /dev/ptmx device, because it's generous like that.

🚨 real talk bestie: new code should NOT try to allocate pseudo-terminals using this interface. it's only here for compatibility with older C libraries that tried to open such devices when posix_openpt(2) was being called, and for running Linux binaries. that's it. that's the whole job. periodt.

πŸŽ€ FILES πŸŽ€

the BSD-style compatibility pseudo-terminal driver uses these device names, and you're gonna want to write them down fr fr:

  • /dev/pty[l-sL-S][0-9a-v] β€” the pseudo-terminal master devices πŸ‘‘
  • /dev/tty[l-sL-S][0-9a-v] β€” the pseudo-terminal slave devices ⛓️
  • /dev/ptmx β€” the control device; when you open it, it returns a file descriptor to a new master pseudo-terminal 🌈

πŸ’€ DIAGNOSTICS πŸ’€

None.

that's the whole section. not a single diagnostic. she said "no thoughts, head empty, no errors." πŸ“


πŸ”₯ SEE ALSO πŸ”₯

go read these next, i'm obsessed:


⭐ HISTORY ⭐

a pseudo-terminal driver appeared in 4.2BSD. ancient. legendary. foundational. we love a pioneer πŸ’œ


πŸ™ˆ BUGS πŸ™ˆ

okay so this is the messy part, and you need to hear it:

  • unlike previous implementations, the master and slave device nodes are destroyed when the PTY becomes unused. so they just… vanish. gone. ghosted. 😭
  • a call to stat(2) on a nonexistent master device will already cause a new master device node to be created. yes, just checking on it resurrects it. main character energy tbh.
  • the master device can only be destroyed by opening and closing it. that's the only way out. πŸ’…
  • the pty driver cannot be unloaded, because it cannot determine if it is being used. it literally doesn't know if anyone's home, so it just… stays. forever. we stan a committed queen πŸ‘‘

mwah πŸ’‹ that's the whole page! this one came from the Debian crew, dated October 28, 2019. take care of her, she's vintage πŸŽ€βœ¨

πŸ“¦ where this page comes from