The concept of TTY, Pty, PTS is reproduced in Linux

Source: Internet
Author: User
Tags telnet program

Basic Concepts:1>TTY (collectively referred to as terminal equipment): The term TTY originates from teletypes, or teletypewriters, which originally refers to a telex typewriter, which is used to read and send information through a serial line with a printer keyboard, which was later replaced by a keyboard and a monitor, So now call terminal more appropriate. 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 do we need a terminal interaction if we telnet to the host or use xterm remotely? Yes, this is the Virtual Terminal pty (pseudo-TTY)3> pts/ptmx (pts/PTMX (pty):p TS (pseudo-terminal slave) is the Pty implementation method, and PTMX (pseudo-Terminal Master) implements Pty with use.
Linux endpoints: Special documentation directories for devices in Linux systems/dev/, the terminal Special equipment documentation generally has the following types:1, serial port terminal (/dev/TTYSN) Serial port terminal (Serial portterminal) 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, since his greatest use was to connect the terminals. The device name corresponding to these serial ports 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 will send 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/The pseudo-terminal (Pseudo Terminal) is a paired logical terminal device (that is, the master and slave devices, and the operations on master are reflected on the slave).
For example/dev/ptyp3 and/DEV/TTYP3 (or/dev/pty/in the device documentation system, respectively)M3 and/DEV/PTY/S3). They are not directly related to the actual physical device. If a program sees PTYP3 (master device) as a serial port device, he reads/The write operation 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. Such
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. Prior to the use of the device documentation System (DEVICEFILESYSTEM), in order to obtain a large number of pseudo-terminal equipment special documents, the use of more complex document name naming method. 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, the 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 into a/dev/pts/-3. This makes it possible to provide a Pty pseudo-terminal when needed. Catalogue/dev/pts is a document system of type devpts and can be seen in the list of loaded document systems. Although "document"/dev/pts/3 appears to be an item in the device documentation system, but in fact 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 x2, #ls/dev/pt*3, close the terminal window under this X and run again; compare the output information two times to understand. In the RHEL4 environment: the output is/dev/ptmx/dev/pts/1 Existence of one (master) to many (slave) cases=========================================================================3, Control terminals (/dev/TTY) If the current process has a control terminal (controllingterminal), then/dev/TTY is the device special document for the control terminal of the current process. You can use the command "Psax" to see which control terminal the process is connected to. For the shell you are logged into,/dev/tty is the terminal you use, the device number is (5,0). Use the command "TTY" to see exactly which actual terminal device he corresponds to. /dev/a TTY is somewhat similar to a connection to a terminal device that is actually used.
4, console terminal (/dev/ttyn,/dev/console)
In Linux systems, computer monitors are often referred to as console terminals. He simulates a type of terminal for Linux ( term=Linux), and there are some device special documents associated with it: Tty0, tty1, Tty2, etc. When you log in on the console, you are using Tty1. Use Alt+[F1―F6] We can switch to Tty2, tty3 and so on when we combine the keys. Tty1tty6, such as virtual terminal, and Tty0 is the current use of the virtual terminal alias, the information generated by the system will be sent to the terminal (also known as Console terminal). Therefore, regardless of which virtual terminal is currently in use, the system information is 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/dev/The following example is tty0 for write operations:
1, # TTY (view current TTY)/dev/tty12, #echo"Test Tty0">/dev/tty0test tty0
5Virtual Terminal (/dev/pts/N) pseudo-terminal in Xwindows mode.

[[email protected] ~]# TTY
/dev/pts/1

/DEV/PTS/1 when connecting remotely to Linux


6other types of Linux systems also exist for many different character devices that have many other types of terminal equipment special documentation. For example, for ISDN devices/dev/Ttyin terminal equipment and so on. Don't repeat it here. FAQ: Terminals and consoles
Q:/dev/What is the console? A:/dev/Console , which is the control console, is the device that interacts with the operating system, and the system outputs some information directly to the console. Users are now allowed to log in to the console only in single-user mode.
Q:/dev/What is a 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/in the current terminalTTY, which will be displayed directly in the current terminal.
Q:/dev/ttys*What is it? A:/dev/ttys*It's a serial terminal.
Q:/dev/pty*What is it? A:/dev/pty*that is, pseudo-terminal, the so-called pseudo-terminal is a logical end device, more used to simulate 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 .../dev/What is 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.
Q:/dev/console is to/dev/.Tty0 's symbolic link? A: Most of the text is now called/dev/console is to/dev/.Tty0 links (including "Linux kernel source Scenario analysis"), but this is not accurate. According to the kernel documentation, in 2.1Before. 71,/dev/console can be linked to/dev/tty0 or other tty* depending on the settings of the system, at 2.1the. 71 version is completely controlled by the kernel. Now you can only log in in single-user mode/dev/Console (can be confirmed by entering the TTY command in single-user mode).
Q:/dev/tty0 and/dev/fb*What's the difference? A: In a system that is not enabled for framebuffer devices, you can use/dev/tty0 access to the video card.
Q: What text A can be consulted about the terminal and the console: can refer to documents in the kernel document/Devices.txt in the section on "TERMINAL devices". In addition, section 8.7 of the Linux kernel source scenario analysis, together with section 3.9 of the Operating systems:design andimplementation (3rd edition, section 3.8), provides a good introduction to the concept and history of terminal equipment. In addition, in the "modernoperating system" also has the introduction of terminal equipment, because and "Operating systems:design andimplementation" the author of the same, so the text content is roughly the same. One thing to note is that the terminal equipment is divided into 3 categories in the Operating Systems:designand implementation, while the modern OperatingSystem is divided into 2 categories, the difference being that the former will be X Terminal as a category. PS: Only 2410 of 2.6 is called ttysac0,9200, or ttyS0.

The concept of TTY, Pty, PTS is reproduced in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.