NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pts vs tty: differences and usage



Hello!
First of all, I hope this topic is still appropriate for this section.
As regards terminals and pseudoterminals, NetBSD seems very similar to Linux. A terminal in a GUI is run into a /dev/ptsx; if the OS is run in text mode, the /dev/ttyx is used instead.
/dev/ptsx (where x is a number in a range of roughly 16 integers) is part of a "UNIX 98 pseudoterminal": it is a slave, associated with a master. An application which needs a terminal will use a couple of master/slave pseudoterminals; it is the case of xterm and other terminal emulators. While the slave is a visible device, the master is not immediately recognizable. Just *one* file in the /dev directory is related to pseudoterminal masters: it is /dev/ptmx (and this time x is the letter, not a generic integer) and it is called the "master clone device".
According to pty(4), "the slave device provides to a process an interface identical to that described in tty(4)". I may understand that when a software (and not a hardware device) needs to use a terminal some kind of mediation is necessary. But I have some questions:
- What is the difference between a hardware device using a terminal and a software applications? Do not they simply both send some interrupt or signal to the kernel at each typed character? 
- Why it was decided to create pseudoterminals, instead of a simple software layer between the application and a normal, conventional tty?
- Why is it necessary to create a master-slave *couple* for every application and not a *unique* terminal?
- The C function posix_openpt(3) "searches for an unused master pseudo-terminal device, opens it, and returns a file descriptor associated with the now used pseudo-terminal device". The slaves are visible and are /dev/ptsx. Why using a "master clone device" (instead of a multitude of master files as the slaves are), returning a file descriptor and not a file path? Having as much masters as the slaves seems to be simpler.
I know that my questions may be wide. Feel free to answer what you can, only if you can and you would like to do it.
Thank you anyway,

Rocky


Home | Main Index | Thread Index | Old Index