Terminal of Linux core concepts

Source: Internet
Author: User

Note:This article is the author's own understanding of the terminal. In order to solve the confusion in his mind, I read some materials and write it. Many local terms are not accurate, and my own experiences are just for reference.

1 terminal Origin

When the computer was invented, there was no display or keyboard. Later, there was no Unix host, and its input and output were connected to a dedicated input and output device through a serial line. This device was called a terminal, and the earliest appearance was a teletype, therefore, the terminal uses three tty letters.

Host --------- (Serial Line) ------------ terminal device (including keyboard, video card, and mouse)

2 terminal control protocol

Terminal devices generally include the keyboard used for input and the display used for output. The host does not directly manage the keyboard and display of the terminal, but treats the terminal as a physical whole, therefore, the host and terminal interact through a set of control commands (Protocols. In Unix, everything is a file, and the same is true for terminal devices. Reading Terminal devices is to get user input, while writing to terminal devices is to output.

It should be noted that Microsoft's DOS and Windows seldom use the concept of terminal, because these systems appear on machines with their own keyboard and display. These systems prefer to directly manage the keyboard and display (handle the keyboard controller and directly write the video memory), rather than using them as a terminal.

There were many early terminal models with different display capabilities and different control commands, which caused a lot of trouble for programming. In order to standardize the display capabilities and control commands of terminals, some standards have emerged: ANSI, VT100, and so on. Slowly, all devices follow these standards for design and implementation. There are also device-independent programming interface libraries, such as termcap and terminfo (/lib/libtinfo. so. These two libraries are still primitive, but they shield control commands from different terminals and do not provide more advanced functions. The less tool relies on libtinfo. so. To facilitate advanced display in character modes such as menus and windows, the famous curses library appears. Editors such as vim and emacs and the info tool are based on the curses library.

3. After the Host Integration Terminal

3.1 Use of built-in keyboard and video card

With the development of computers, almost all machines have built-in keyboards and graphics cards. In this case, the machine itself is integrated with the host and terminal. There are two ways to use the device: one is to use the built-in keyboard and video card in the traditional terminal mode, and the other is to directly control the keyboard and video card. The advantage of the first method is that the program that used the terminal can run directly without modification, at the cost of simulating a terminal device, maps operations on the terminal device to operations on the keyboard and video card.

Program ------- simulated terminal ------- built-in keyboard and video card

In the second method, the disadvantage is that the program that used the terminal must be rewritten. The advantage is that you can make full use of the performance of the built-in graphics card, not limited to the limitations of ANSI, VT100 and other terminal capabilities. Since ANSI and VT100 appeared very early, they do not provide pixel control. Therefore, all graphical interface programs are based on the second method.

3.2 Linux terminal

For Linux systems, the text mode still supports the traditional terminal mode to use the built-in keyboard and graphics card, and simulates multiple terminals, you can use Alt + F1, alt + F2 ,... to switch. In this way, you can use a terminal program that uses a real serial port to connect to the terminal device (which is rarely used now), or you can use a virtual terminal simulated by a built-in graphics card and keyboard. In addition, Linux provides pure virtual terminal devices on the kernel layer to support network programs, such as ssh and telnet. The reason for this is that such a terminal does not have the corresponding hardware, and the more appropriate name is the Pseudo Terminal (pty ).

Putty program on Windows platform (analog terminal) -------- network ----- Pseudo Terminal ------ Linux host

Xterm Program (analog terminal) in Linux platform X ----- Pseudo Terminal --- Linux host

As mentioned earlier, the terminal only supports text display. Therefore, the graphic environment X in Linux also directly controls the keyboard and video card. Note that there is a framebuffer mode in Linux. After startup, you can use the video card in both the terminal mode and the graphic mode.

Program -------- frambuffer API --------- directly write the video memory

Program -------- curses API --- (terminal command) ---- simulate terminal (/dev/tty1) -------- ing to write video memory

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.