What are the responsibilities of each Pseudo-Terminal (PTY) component (software, master side, slave side)?
I am trying to figure out how a tty works 1 (the work-flow and responsibilities of each elements). I have read several interesting articles about it, but there are still some blurry areas.
This is what I understand so far:
- The emulated terminal makes different system calls to /dev/ptmx. the master part of the pseudo-terminal.
- The master part of the pseudo terminal allocates a file in /dev/pts/[0-N]. corresponding to the obsolete serial port, and "attaches" a slave pseudo terminal to it.
- The slave pseudo terminal keeps information such as session Id, foreground job, screen size.
ptmxany purpose besides allocating the slave part? Does it provide some kind of "intelligence". or the emulated terminal (xterm for instance) has all the intelligence of behaving like a terminal?
- Why does xterm has to interact with the master part, as it only forwards the stdout and stdin of the slave part? Why can't it directly write and read from the pts file ?
- Is a session ID always attached to one pts file and vice versa? Could I type a ps command and found 2 sessionId for the same /dev/pts/X ?
- What other information does the pts store? Does Xterm update all fields by himself, or does the ptm add some "intelligence" on it?