Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux basic terminal, console, tty, pty introduction

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. basic concepts

1 、 tty

Tty (general name for terminal equipment): the word tty comes from teletypes, or teletypewriters, which originally refers to a teletypewriter, something that reads and sends information through a printer keyboard through a serial line, which is later replaced by a keyboard and display, so it is now more appropriate to call a terminal. Terminal is a kind of character device, which has many types, and tty is usually used to refer to various types of terminal devices.

2 、 pty

Pty (pseudo terminal, virtual terminal): but don't we also need a terminal interaction if we remotely telnet to the host or use xterm? Yes, this is the virtual terminal pty (pseudo-tty)

3 、 pts/ptmx

Pts/ptmx (pts/ptmx is used in conjunction with pty): pts (pseudo-terminal slave) is the implementation method of pty, and it is used with ptmx (pseudo-terminal master) to implement pty.

II. Terminal special equipment files

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

1. Serial port terminal (/ dev/ttySn)

A serial port terminal (Serial Port Terminal) is a terminal device connected using a computer serial port. The computer treats each serial port as a character device. There was a time when these serial port devices were often called terminal devices because their greatest use at that time 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), etc., and the device numbers are (4je 0), (4je 1), etc., respectively, corresponding to COM1 and COM2 under the DOS system. To send data to a port, you can redirect standard output to these special file names 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 (Pseudo Terminal) are pairs of logical end devices (that is, master and slave devices, and operations on master are reflected on the slave).

For example, / dev/ptyp3 and / dev/ttyp3 (or / dev/pty/ m3 and / dev/pty/s3 in the device file system, respectively). They are not directly related to the actual physical equipment. If a program treats ptyp3 (master device) as a serial port device, its read / write operations to that port will be reflected in another ttyp3 (slave device) corresponding to the logical terminal device. Ttyp3 is the logical device used by another program to read and write. Telnet host A communicates with host A through the login program of "pseudo terminal".

3. Control terminal (/ dev/tty)

A control terminal is a terminal controller that can control one set of equipment or several sets of equipment.

If the current process has a control terminal (Controlling Terminal), then / dev/tty is the device special file of the control terminal of the current process. You can use the command "ps-ax" to see which control terminal the process is connected to. For the shell,/dev/tty you are logged in to is the terminal you are using, the device number is (5pc0). Use the command "tty" to see which actual end device it corresponds to. / dev/tty is somewhat similar to a connection to the actual terminal device used.

4. Console terminal (/ dev/ttyn, / dev/console)

In Linux systems, computer monitors are often called console terminals (Console). It simulates a terminal (TERM=Linux) of type Linux and has some device-specific files associated with it: tty0, tty1, tty2, and so on. When you log in on the console, you are using tty1. When using the Alt+ [F1-F6] key combination, we can switch to tty2, tty3, etc. Tty1-tty6 and so on are called virtual terminals, and tty0 is an alias of the currently used virtual terminals, and the information generated by the system will be sent to the terminal (also called console terminal at this time). Therefore, no matter which virtual terminal is currently in use, the system information will be sent to the console terminal. / dev/console is the console, which is a device that interacts with the operating system, and the system outputs some information directly to the console. Currently, users are allowed to log on to the console only in single-user mode.

5. Virtual terminal (/ dev/pts/n)

Pseudo terminal in X windows mode (graphical interface). If I use konsole under Kubuntu, I am using a virtual terminal, and / dev/pts/1 can be seen with the tty command.

6. Other types

There are also many other kinds of terminal device special files for many different character devices in the Linux system. For example, / dev/ttyIn terminal devices for ISDN devices and the like. I won't repeat it here.

Tty devices include: virtual console, serial port and pseudo terminal devices. / dev/tty represents the current tty device. Enter echo "hello" > / dev/tty in the current terminal and it will be displayed directly in the current terminal.

The terminal, console, tty and pty under the Linux system are briefly introduced. Although they are the basic contents, they are very important. We must understand them.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report