TTY is the abbreviation of Teletype.
Terminals are character-type devices. There are multiple types of terminal devices. Teletype was one of the first terminal devices to emerge, much like a teletypewriter (or 򕒺 ), which is produced by Teletype. The device name is stored in the special file directory /dev/. The following types of special device files are available:
1. Serial port terminal (/dev/ttySn)
A serial port terminal is a terminal device connected through a computer serial port. The computer sees each serial port as a character device. There was a time when these serial port devices were often referred to as terminal devices because their main purpose was to connect terminals. The device names corresponding to these serial ports are /dev/tts/0 (or /dev/ttyS0), /dev/tts/1 (or /dev/ttyS1), and the device numbers are (4, 0) and (4, respectively. 1) Corresponds to COM1 and COM2 in the DOS system. To send data to a port, you can redirect the standard output to these special filenames on the command line. For example, typing: echo test > /dev/ttyS1 at the command-line prompt sends the word "test" to the device connected to the ttyS1 (COM2) port.
2. Pseudo terminal (/dev/pty/)
Pseudo terminals are pairs of logical terminals, such as /dev/ptyp3 and /dev/ttyp3. (or /dev/pty/m3 and /dev/pty/s3, respectively, in the device file system). They are not directly related to the actual physical device. If a program sees ttyp3 as a serial port device, its read/write operations to that port are reflected on another of the logical terminal device pairs (ttyp3). Ttyp3 is another logical device that programs use for reading and writing operations. This allows two programs to communicate with each other through this logical device, while one of the programs using ttyp3 thinks it is communicating with a serial port. This is much like a pipe operation between logical device pairs.
For ttyp3 (s3), any program designed to use a serial port device can use that logical device. However, programs that use ptyp3, need to be specifically designed to use ptyp3 (m3) logical devices.
For example, if someone uses a telnet program to connect to your computer on the Internet, the telnet program may start connecting to the device ptyp2 (m2) (on a pseudo-terminal port). In this case, a Getty program should run on the corresponding ttyp2 (s2) port. When telnet obtains a character from the remote end, the character is transferred to the Getty program through m2 and s2, and the Getty program returns the login: character string to the network through s2, m2, and telnet. In this way, the login program communicates with the telnet program through a "pseudo-terminal". Using the appropriate software, it is possible to connect two or more pseudo-terminal devices to the same physical serial port.
Before using the device filesystem, HP-UX AIX uses a complex naming scheme to obtain a large number of special files of pseudo-terminal devices.
3. Control terminal (/dev/tty)
If the current process has a control terminal, /dev/tty is the special device file of the control terminal of the current process. You can run the ps –ax command to check which control terminal the process is connected to. For the shell, you log in to, /dev/tty is the terminal you use, and the device number is (5, 0). You can run the tty command to view the actual terminal device corresponding to the tty. /dev/tty is somewhat like a connection to the actual terminal device being used.
4. Console terminal (/dev/ttyn, /dev/console)
In UNIX systems, a computer monitor is often referred to as a console terminal. It emulates a terminal of type Linux (TERM=Linux) and has some device-specific files associated with it: tty0, tty1, tty2, and so on. When you log in to the console, you use tty1. Press Alt+[F1-F6] to switch to tty2, tty3, etc. tty1 – tty6 are called virtual terminals, and tty0 is an alias of the current virtual terminal. The information generated by the system is sent to the terminal. Therefore, system information is sent to the console terminal regardless of which virtual terminal is currently in use.
You can log in to different virtual terminals, so the system can have several different sessions at the same time. Only the system or superuser root can write to /dev/tty0.
5. Other types
There are also many other types of terminal device special files for many different character devices. For example, the /dev/ttyIn terminal device for ISDN devices.
