Here is my bash session:
lrwx------ 1 stas stas 64 Mar 5 18:18 0 -> /dev/pts/0
lrwx------ 1 stas stas 64 Mar 5 18:18 1 -> /dev/pts/0
lrwx------ 1 stas stas 64 Mar 5 18:18 2 -> /dev/pts/0
We see that bash both reads from and writes to /dev/pts/0
. My question is: how come the process doesn't read what it just wrote there? What makes only master pty
receive the data?
/dev/pts/0
is not a regular file but a character device node, as can be seen in the first column ofls -l
output: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):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.