Analysis on tty, pty, and pts
First, let's start with the concept. The so-called tty is the abbreviation of TeletypeWriter. Its Chinese translation is a telex typewriter. Its main function is to print and read information, later, it was replaced by a keyboard and a display. However, tty's common understanding is terminal.
What is a terminal? It is an electronic or electromechanical hardware device that can be used to input data to a large host and display data from the host. In the early days of computers, many computers connect to several terminal consoles. The hardware structure of these terminals is very simple. They do not execute computing tasks. They are only responsible for Inputting User commands, and return the computation results.
Our telex typewriter can be understood as the earliest computer terminal. Of course, with the keyboard, mouse, and display, this is history. At this time, the concept of the terminal has also changed slightly, because a previous device can complete two functions, but now it is divided into two devices, that is, the current display no longer contains the character generation function.
Later, we introduced the virtual terminal function, which is pty. It is short for the pseudo-Do tty, which is also called a pseudo Terminal, for example, remote telnet can be considered as a Pseudo Terminal.
In the process of implementing pty, we introduced two more concepts:
(1) Since we want to implement pty, some devices need to be connected. They can be understood as ptmx and can be understood as a master.
(2) When some devices need active connection, they can be understood as pts and slave.
There are two naming formats for the pty Virtual Devices:
(1) For BSD, slave generally uses the/dev/tty [p-za-e] [0-9a-f] format, the master generally uses the/dev/pty [p-za-e] [0-9a-f] format.
(2) For Unix98, slave generally uses/dev/pts/n, and the second master generally uses/dev/ptmx.
However, after X-Windows is enabled, this will happen to virtual terminals. If we use a Linux operating system, there will be virtual terminals such as pts/0.