6

I have found two contradictory images of how a pseudo terminal (pty) works.

The first image shows that the process on the slave side of a pty talks to the line discipline:

enter image description here

The second image shows that the process on the slave side of a pty talks to the slave tty driver:

enter image description here

Which image is correct?

paul
  • 475
  • 5
  • 10
  • 1
    IMHO first digram seems wrong. Because the line terminal emulator suppose to be in between Hardware and process. in First image if you swap 'terminal line discipline' with 'pseudo terminal slave' it will be right. – Devidas May 30 '17 at 12:18

1 Answers1

5

The second image is correct. (BTW, it comes from here.)

From the accepted answer on this question:

The line discipline is a software module (residing in the driver, in the kernel) pushed on top of a serial/pty device that sits between that device and the line/wire (the master side for a pty).

(...)

You can see the effect of disabling the tty line discipline by issuing stty raw -echo (note that the bash prompt or other interactive applications like vi set the terminal in the exact mode they need, so you want to use a dumb application like cat to experience with that). Then, everything that is written to the slave terminal device makes it immediately to the master side for xterm to read, and every character written by xterm to the master side is immediately available for reading from the slave device.

See also this post about ttys.

Archie
  • 123
dr_
  • 29,602
  • If the line discipline is on top of the underlying device, then the first image, which has exactly that, is the correct one. – JdeBP Aug 08 '17 at 11:38
  • 2
    It looks the third link changed to https://www.yabage.me/2016/07/08/tty-under-the-hood/ – minghua Feb 18 '20 at 05:31