Reprint: http://blog.sina.com.cn/s/blog_638ac15c01012e0v.html
Basic Concepts:
1> TTY (collectively referred to as terminal equipment):
The word "TTY" originates from teletypes, or teletypewriters, which originally refers to a telex typewriter, which is used to read and send information through a printer keyboard through a serial line, which is later replaced by a keyboard and a display, so it is now more appropriate to call the terminal.
Terminal is a type of character device, he has a variety of types, usually using a TTY abbreviation for various types of terminal equipment.
2> Pty (Virtual terminal):
But what if we don't need a terminal interaction remotely when we telnet to the host or use xterm? Yes, this is the Virtual Terminal Pty (Pseudo-tty)
3> PTS/PTMX (PTS/PTMX combined to achieve pty):
PTS (pseudo-terminal Slave) is the implementation of Pty, and PTMX (Pseudo-terminal Master) implements Pty with use.
Linux Terminal:
In the device special document directory of the Linux system/dev/, the terminal Special equipment documentation generally has the following types:
1. Serial port terminal (/DEV/TTYSN)
The serial port terminal (Serial Port Terminal) is a terminal device connected using a computer serial port. The computer sees each serial port as a character device. For a while these serial port devices are often referred to as terminal equipment because
At that time his greatest use was to connect the terminal. The serial port corresponding to the device name is/dev/tts/0 (or/DEV/TTYS0),/DEV/TTS/1 (or/dev/ttys1), etc., the device number is (4,0), (4,1), respectively, corresponding to the DOS system COM1, COM2 and so on. To send data to a port, you can redirect standard output to these special document names on the command line. For example
At the command-line prompt, type: Echo Test >dev/ttys1 sends the word "test" to the device connected to the TtyS1 (COM2) port. Can be connected to the serial port to experiment.
2. Pseudo Terminal (/dev/pty/)
Pseudo-terminal (Pseudo Terminal) is a paired logical terminal device (that is, the master and slave devices, the operation of Master will be reflected on the slave).
For example,/DEV/PTYP3 and/DEV/TTYP3 (or/dev/pty/m3 and/DEV/PTY/S3 in the device documentation system). They are not directly related to the actual physical device. If a program considers PTYP3 (master device) as a serial port device, his read/write operation on the port is reflected on the other TTYP3 (slave device) corresponding to the logical terminal. The TTYP3 is another logical device that the program uses for read and write operations. In this way, two programs can communicate with each other through this logical device, and one of the programs that uses TTYP3 thinks that it is communicating with a serial port. This is like a pipe operation between logical device pairs. For TTYP3 (S3), any program designed to use a serial port device can use the logical device. For programs that use PTYP3, however, you need to specifically design a ptyp3 (m3) logical device.
For example, if someone connects to your computer using a Telnet program on the Internet, the Telnet program may start connecting to the device Ptyp2 (m2) on a pseudo-terminal port. At this point, a Getty program should run on the corresponding TTYP2 (S2) port. When Telnet obtains a character from the far end, the character is passed to the Getty program via M2, S2, and the Getty program returns the "login:" String information to the network via S2, M2, and telnet. In this way, the login program and the Telnet program communicate through a "pseudo terminal". By using the appropriate software, two or more pseudo-terminal devices can be connected to the same physical serial port.
In order to obtain a large number of pseudo-terminal equipment special documents before using device filesystem, a more complex document name naming method is used. Because there are only 16 Ttyp (TTYP0―TTYPF) of the device documentation, in order to get more logical device pairs, like Q, R, S and other characters are used instead of p. For example, TTYS8 and Ptys8 are a pseudo-terminal device pair. But this naming method is still used in Linux systems such as Redhat.
However, Unix98 on a Linux system does not use the method described above and uses the "ptymaster" approach, such as/DEV/PTM3. His counterpart will be automatically created as a/DEV/PTS/3. This makes it possible to provide a Pty pseudo-terminal when needed. Directory
/dev/pts is a document system of type devpts and can be seen in the list of loaded document systems. Although the document/DEV/PTS/3 appears to be an item in the device documentation system, he is a completely different document system.
That is: TELNET---> TTYP3 (s3:slave)---> PTYP3 (m3:master)---> GETTY
=========================================================================
Experiment:
1. Open one or n terminal windows under X
2, #ls/dev/pt*
3, close the terminal window under the X, run again, compare two times output information to understand.
In RHEL4 Environment: one (Master) to many (slave) for the output of/DEV/PTMX/DEV/PTS/1
=========================================================================
3. Control Terminal (/dev/tty)
Such as
The current process has a control terminal (controlling
Terminal), then/dev/tty is the device special document for the control terminal of the current process. The ability to use the command "PS
Ax "to see which control terminal the process is connected to. The shell,/dev/tty you are logged into is the terminal you are using, and the device number is (5,0). Use the command "TTY" to view his
specific to which actual terminal equipment. The/dev/tty is similar to a connection to a terminal device that is actually used.
4. Console Terminal (/dev/ttyn,/dev/console)
In Linux
In the system, a computer monitor is often referred to as the console terminal
(Console). He simulates a type of terminal (Term=linux) of Linux, and has some device special documentation associated with it: Tty0, Tty1, Tty2
such as When you log in on the console, you are using Tty1. With Alt+[f1―f6], we were able to switch to Tty2, Tty3, and so on. TTY1TTY6, etc.
Called a virtual terminal, and Tty0 is the alias of the virtual terminal that is currently used, the information generated by the system is sent to the terminal (also called the console terminal). So regardless of which virtual end is currently in use
System information will be sent to the console terminal. You can log on to different virtual terminals, allowing the system to have several different session periods at the same time. Only the system or the ultimate user root can
The following example is/dev/tty0 for write operations:
1. # TTY (view current TTY)
/dev/tty1
2, #echo "Test tty0" >/dev/tty0
Test Tty0
5 Virtual terminal (/dev/pts/n)
Pseudo-terminal in Xwindows mode.
6 Other types
The Linux system also has many other types of terminal Equipment special documentation for many different character devices. For example,/dev/ttyin terminal equipment for ISDN devices. Don't repeat it here.
FAQ: Terminals and consoles
What is Q:/dev/console?
A:/dev/console is the console, which is the device that interacts with the operating system, and the system outputs some information directly to the control console. Users are now allowed to log in to the console only in single-user mode.
What is Q:/dev/tty?
A:tty equipment includes Virtual Console, serial port together with pseudo terminal.
/dev/tty represents the current TTY device and enters echo "Hello" >/dev/tty in the current terminal, which is displayed directly in the current terminal.
What is q:/dev/ttys*?
A:/dev/ttys* is a serial terminal device.
What is q:/dev/pty*?
A:/dev/pty* is pseudo-terminal, the so-called pseudo-terminal is a logical end-device, more used to simulate the terminal program. For example, the terminal we opened under X window, along with the way we log in to a Linux host using Telnet or SSH in Windows, is using the Pty device (which is accurate in using Pty from the device).
Q:/dev/tty0 and/dev/tty1 ... what is/dev/tty63? What's the difference between them?
A:/dev/tty0 represents the current Virtual console, while/dev/tty1, for example, represents the first virtual console, such as when using ALT+F2 for conversion, the system's Virtual Console is/dev/tty2, and the current console points to/dev/tty2
Q: How do I determine which terminal (or console) is currently located?
A: Use the TTY command to determine the current terminal or console.
is q:/dev/console a symbolic link to/dev/tty0?
A:
Most of the text now says/dev/console is a link to/dev/tty0 (including "Linux kernel source Scenario analysis"), but that's not true. According to the internal
Nuclear documentation, prior to 2.1.71,/dev/console can be linked to/dev/tty0 or other tty* based on the settings of the different systems, after the 2.1.71 Release
Fully controlled by the kernel. You can now log in to/dev/console in single-user mode (you can confirm by entering the TTY command in single-user mode).
What is the difference between q:/dev/tty0 and/dev/fb*?
A: In a system that is not enabled on the framebuffer device, you can access the video card using/dev/tty0.
Q: What text can I refer to the distinction between terminal and console?
A:
Ability to refer to the documents/devices.txt in the kernel documentation for "TERMINAL devices"
The chapters. In addition, section 8.7 of the Linux kernel source scenario analysis, together with the Operating systems:design and
Implementation 3.9 (3rd edition of Section 3.8) is a good introduction to the concept and history of terminal equipment. In addition, the modern
Operating system also has an introduction to terminal equipment, due to the Operating systems:design and
Implementation is the same as the author, so the text content is roughly the same. One thing to be aware of is the Operating systems:design
and implementation the terminal equipment into 3 categories, and the "modern Operating
System divides terminal hardware devices into 2 categories, the difference being that the former takes X terminal as a category.
Ps:
Only 2410 of 2.6 is called ttysac0,9200, or ttyS0.
Conceptual differences between TTY, Pty, and PTS in Linux