When process writes to pseudoterminal slave, why it doesn't read what it wrote?

Solution 1:

/dev/pts/0 is not a regular file but a character device node, as can be seen in the first column of ls -loutput:

v
crw--w---- 1 tilman tty  136, 0 Mär  6 20:25 /dev/pts/0

As such, read and write operations are not accessing some file on disk, but are instead processed by a piece of software called a device driver which can do pretty much anything its author wanted it to do, from just nothing at all (as in the case of the driver behind /dev/null) to elaborate actions on some piece of hardware in your computer (as in the case of actual hardware drivers.)

In the specific case of /dev/pts/0 that driver is written to (very simplified):

  • If a process writes some data to the slave device, provide that data as the result to the next read operation on the master device.
  • If a process writes some data to the master device, provide that data as the result to the next read operation on the slave device.

It is not written to provide data written to the slave device back to a read operation on the slave device, therefore that does not happen.