Based on what I have read about pseudoterminals in Linux, there are two types of pseudoterminals: BSD-style pseudoterminals (which is deprecated) and UNIX 98 pseudoterminals.
I have created two images that shows my understanding of these two types of pseudoterminals.
The following image shows how the BSD-style pseudoterminals works (please correct me if the image is wrong):
This type of pseudoterminals is not hard to understand, each terminal is connected to a unique master driver.
But in the UNIX 98 pseudoterminals, things are a little more confusing. The following image shows how I think this type of pseudoterminals works:
So basically all terminals use the same master driver (/dev/ptmx
), but I am not sure how the master driver knows how to do the following:
If data is being sent from one of the terminal processes, how does the master driver knows to which TTY slave driver the data should be passed to?
If data is being sent from one of the TTY slave drivers, how does the master driver knows to which terminal process the data should be passed to?
Does the master driver knows how to do this in the way that I have shown in the image (i.e. the master driver have a mapping table that maps each terminal PID to its corresponding TTY slave driver)?