Do you know the Linux console, terminal and shell and their relationship?

When working with Linux, we often come across the concept of terminal and shell. For example, in the desktop version of Ubuntu, we can right-click the desktop and click “Open Terminal” to open the terminal. At this point, we can enter Linux commands in the terminal. One might ask, isn’t this a typo? So what’s the relationship between the terminal and the shell?

When working with Linux, we often come across the concept of terminal and shell. For example, in the desktop version of Ubuntu, we can right-click the desktop and click “Open Terminal” to open the terminal. At this point, we can enter Linux commands in the terminal. One might ask, isn’t this a typo? So what’s the relationship between the terminal and the shell?

Do you know the Linux console, terminal and shell and their relationship?

1 What is a terminal

For what is a terminal, let’s look at a definition first. It can be seen that the terminal is an input and output device, which can be simply understood as a mouse, a keyboard and a monitor. But this seems to be somewhat different from the concept of terminal in Linux. Let me explain it.

a combination of a keyboard and output device (such as a video Display unit) by which data can be entered into or output from a computer or Electronic communications system.

But if you want to understand what a terminal is, you need to start from the “ancient” period. Before 1970, there were no personal computers at that time. That one uses only mainframes and minicomputers, that is, a computer the size of a wardrobe. The more famous computers at that time were the DPD-7 and the GE-45.

At that time, Ken Thompson and Dennis Ritchie (the two great gods in the picture below) were responsible for developing a new operating system on DPD-7, yes, the UNIX operating system. In order to improve the efficiency of computer use, they intend to make this operating system support multiple users using the computer at the same time.

However, monitors at the time were a very expensive device, and it was unlikely that everyone had one. So the two came up with a workaround. They opted for cheap teletypes as terminal equipment. This teletypewriter (TeleType) is ASR33, which is the device shown in the figure below.

The device enters information into the computer via the keyboard, and the computer’s output is printed on the paper above. In this way, UNIX became the first operating system in the world to support multiple users, and ASR33 became the first Unix terminal. Later, the abbreviation TTY was used to denote a Unix or Linux terminal.

As technology develops and hardware prices continue to drop, terminals are also becoming more advanced and cheaper. In 1970, DEC invented the VT05 video terminal. It is the following stuff, you can see that she has a small monitor. It is also more and more like the keyboard display now.

We have learned that the so-called terminal is actually a physical device, that is, the input and output device of the computer.

2 What is a console

In the 1970s, the terminal was connected to the host by a cable. At the same time, there is a special terminal on the host, which is directly integrated on the host. This special terminal is called the console. The special feature of this terminal is that it can only be used by administrators. Each computer has only one console, which is not much different in appearance from a normal terminal, but the most important thing is that the console can do some things that normal terminals cannot.

For example, when the operating system fails to start, it will print some information to the console, but the terminal will not receive the information. Also, when the operating system is started in single-user mode, we can only log in by using the console. At this time, other terminals do not have permission to log in.

3 Terminal Emulators for Linux Operating Systems

Earlier we learned that the terminal is actually a hardware device, but earlier we can use the menu to open a terminal (Open Terminal) on Ubuntu. In fact, the window we open is also a terminal. We call this terminal a terminal emulator, which uses software to simulate a terminal device. Sometimes we call it a virtual terminal.

If you are using gnome terminal, we can look at its help Q&A with the following command.

man gnome-terminal

It can be seen that gnome-terminal is a terminal emulation program, and its function is to access the Unix shell.

gnome is used to emulate Xterm, and Xterm itself is a terminal emulator. It emulates a VT102 physical terminal.

There are many ways to open the Linux virtual terminal. If we are using the desktop version of Linux, that is, the graphical interface version. Then usually we can open a command line terminal by command. As follows.

In addition, when the Linux operating system starts up, there are 7 virtual terminals by default. These virtual terminals are not the virtual terminals opened on the desktop as mentioned above, but are displayed directly through the monitor. We can switch between these terminals through shortcut keys, such as Ctrl+Alt+F1 to switch to the first terminal, Ctrl+Alt+F2 to switch to the second terminal, and so on Ctrl+Alt+F7 to switch to seventh terminal. Usually, for a graphical interface, the seventh is a graphical terminal, and the others are text terminals.

Through the previous introduction, we have understood concepts such as terminals, controllers and virtual terminals from the outside. Also have an understanding of virtual terminals in the Linux operating system. Next we will go further into the internals of Linux.

4 What is a Shell

In fact, we have introduced the content of Shell in the previous article. Shell is actually an application program that implements the interface that users access to the operating system. For example, our common management files, users and network resources, etc., are all done through Shell.

Shell is an application, and it has many specific implementations, the more common ones include Bash, Zsh, Csh, and Ksh.

We learned earlier that the terminal is a physical device, which is used by the user to input and present information, and the virtual terminal we are currently using is a simulation of the physical device. Shell is used to execute user commands. In this way, we can now easily understand the relationship between the terminal and the shell.

If we open a virtual terminal through the desktop version, the relationship between the terminal and the Shell is shown in the following figure.

If we are not connected through a local device, but access the computer through the network, then the relationship is shown in the following figure. It can be seen that there is a pty component here that plays a key role, which establishes the association between the two.

1tty, pty and pts in Linux system

Earlier we introduced the terminal, console and shell from a conceptual level. But what are these concepts like in the Linux operating system? What is the relationship between them?

Tty has been introduced earlier, it is a terminal, that is, a collection of input and output devices. At present, in Linux, users interact with computers through virtual terminals. Therefore, in Linux, tty is actually a virtual terminal, which can be understood as a piece of software. If we hold down Ctrl+Alt+F5 at the same time, we can switch to virtual terminal 5, as follows.

In the Linux operating system, the overall architecture of the software is a bit more complicated, because Linux not only supports virtual terminals, but also physical peripherals that can support keyboards and displays, and supports connections through networks such as telnet or ssh. The figure below gives a complete example.

In order to support different types of access methods, the concept of a pseudo terminal, that is, pty, is implemented in Linux. where p is an abbreviation for pseudo.

The pseudo terminal is divided into two parts, as shown in the figure above, including master and slave. Among them, the master realizes the adaptation of different access methods, it realizes the analysis of messages from different devices or software, and transmits the results to the slave; and the slave is actually a virtual terminal, which realizes the interaction with the shell. In other words, ptsiu is a terminal device.

It may still be difficult to understand. Let’s take a specific example. For example, telnet realizes the management of remote computers. In fact, the client is sending various strings, which are sent to the telnet daemon through the network, and then the telnet daemon calls the master. Function implementation analysis.

Today, we mainly introduce concepts such as terminal, console and shell from the level of concept and architecture, and introduce common names such as tty, pty and pts in the Linux operating system. Later, we will use a specific example to let everyone understand the above architecture more clearly.

The Links:   LM260WU2-SLA1 M170EG01-V1

Related Posts