我发现了伪终端(pty)如何工作的两个矛盾图像.
第一张图显示pty从属端的进程与行规则对话:
第二个图像显示pty从属端的进程与slave tty驱动程序通信:
哪个图像是正确的?
解决方法:
第二张图片是正确的. (顺便说一句,它来了from here.)
从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.
另见this post关于ttys.