Differences between Linuxttyptypts concepts

Source: Internet
Author: User
Article Title: Linuxttyptypts concept difference. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Basic concepts:

1. tty (collectively referred to as the terminal device ):

Tty is derived from Teletypes or teletypewriters. Originally, it refers to a telex typewriter, which reads and sends messages through a printer keyboard through a serial line. Later, it was replaced by a keyboard and a display, so now it is more appropriate to call the terminal.

A terminal is a type of terminal device. It has multiple types and generally uses tty for short.

2. pty (virtual terminal ):

But if we remotely telnet to the host or use xterm, do we still need a terminal to interact? Yes, this is the virtual terminal pty (pseudo-tty)

3. pts/ptmx (combining pts/ptmx to implement pty ):

Pts (pseudo-terminal slave) is the implementation method of pty. It is used with ptmx (pseudo-terminal master) to implement pty.

Linux terminal:

In the special file directory/dev/of a Linux system device, there are generally the following types of special device files on the terminal:

1. Serial Port Terminal (/dev/ttySn)

The Serial Port Terminal (Serial Port Terminal) is a Terminal device connected by a computer Serial Port. The computer regards each serial port as a character device. For some time, these serial port devices are usually called terminal devices, because at that time they were used to connect terminals. The device names corresponding to these serial ports are/dev/tts/0 (or/dev/ttyS0),/dev/tts/1 (or/dev/ttyS1), etc, the device numbers are (), (), and so on, respectively, corresponding to COM1 and COM2 in the DOS system. To send data to a port, You can redirect the standard output to these special file names on the command line. For example, if you type echo test>/dev/ttyS1 at the command line prompt, the word "test" is sent to the device connected to the ttyS1 (COM2) port. Can be connected to the serial port for the experiment.

2. Pseudo Terminal (/dev/pty /)

The Pseudo Terminal is a pair of logical Terminal devices (namely, the master and slave devices, and the operations on the 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 file system ). They are not directly related to physical devices. If a program regards ptyp3 (master device) as a serial port device, the read/write operations on the port are reflected in another ttyp3 (slave Device) corresponding to the logical terminal device. Ttyp3 is the logical device used by another program for read/write operations.

In this way, two programs can communicate with each other through this logical device, and one of the programs using ttyp3 thinks they are communicating with a serial port. This is like a channel operation between logical device pairs. For ttyp3 (s3), any program designed to use a serial port device can use this logical device. However, for programs that use ptyp3, a dedicated design is required to use the ptyp3 (m3) logical device.

For example, if someone uses a telnet program to connect to your computer online, the telnet program may start to connect to the device ptyp2 (m2) (a Pseudo Terminal port ). At this time, a getty program should run on the corresponding ttyp2 (s2) port. When telnet obtains a character from the remote end, the character is passed to the getty program through m2 and s2, the getty program returns the "login:" string information to the network through s2, m2, and telnet. In this way, the login program communicates with the telnet program through the "Pseudo Terminal. By using appropriate software, you can connect two or more Pseudo Terminal devices to the same physical serial port.

Before using the device filesystem, a complicated file name naming method was used to obtain a large number of special files of Pseudo Terminal devices. Because there are only 16 ttyp (ttyp0-ttypf) device files, to get more logical device pairs, use characters such as q, r, s to replace p. For example, ttys8 and ptys8 are Pseudo Terminal Device pairs. However, this naming method is still used in Linux systems such as RedHat.

However, Unix98 on Linux does not use the above method, but uses the "pty master" method, such as/dev/ptm3. Its corresponding end is automatically created as/dev/pts/3. In this way, a pty Pseudo Terminal can be provided as needed. Directory/dev/pts is a file system of the devpts type and can be seen in the list of loaded file systems. Although "file"/dev/pts/3 seems to be one of the device's file systems, it is actually a completely different file system.

That is: TELNET ---> TTYP3 (S3: slave) ---> PTYP3 (M3: master) ---> GETTY

========================================================== ======================================

Lab:

1. open one or N terminal windows under X

2. # ls/dev/pt *

3. Close the terminal window under X and run it again. Compare the output information twice.

In the RHEL4 environment: the output is/dev/ptmx/dev/pts/1. One (master) to multiple (slave) conditions exist.

========================================================== ======================================

3. control terminal (/dev/tty)

If the current process has a control Terminal (Controlling Terminal),/dev/tty is the device special file of the control Terminal of the current process. Can I use the command "ps? Ax to check which control terminal the process is connected. For the shell you log on to,/dev/tty is the terminal you are using, and the device number is (5, 0 ). Run the "tty" command to check which actual terminal device it corresponds. /Dev/tty is similar to a connection to the actually used terminal device.

[1] [2] Next page

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.