1. Introduction to the TTY subsystem

img
Personal homepage: Dong Ge talks about technology
I am Dong Ge, a new star creator in the embedded field
Creation concept: Focus on sharing high-quality embedded articles, so that everyone can read something!
img

1. TTY introduction

TTY, a word derived from Teleprinter, translated as a teleprinter, used to represent a computer terminal device in the early days.

Now we usually use TTYit, which is a general term for various (physical/virtual) terminals!

LinuxThe terminal equipment of the system is generally divided into four types: console terminal , pseudo terminal , serial port terminal and other types .

Let's learn more about these Linuxcommonly used terminals and Linux TTY Frameworklay the foundation for learning!

cbe366c77f71c68a0664f1805e7e5856

 

2. Console terminal

Console terminals include: system console, current console, and virtual console.

2.1 System Console

The system console, which is Linuxbelow us /dev/console, is the device that interacts with the operating system, and the information generated by the system is sent to the device.

Currently only in single-user mode, users are allowed to log in to the console /dev/console.

consoleThere is the concept of buffering, which provides printouts to the kernel. The kernel loads the content to be printed into the buffer __log_buff, and then points the console to an activated terminal to determine where to print. console points to the active terminal .

For example, when we start the kernel, the parameters passed in console=ttyS1point the console terminal to the ttyS1serial port device.

 

2.2 Current Console

This is the concept in the application, if the current process has a controlling terminal (Controlling Terminal), then it /dev/ttyis the device file of the current process console .

For the login Shell, /dev/ttyit is the console you are using, and the device number (5, 0) /dev/ttywill be mapped to the current device (you can use the command ttyto check which actual physical console device it corresponds to), and /dev/ttythe output will only be displayed in the current on the working terminal.

You can enter commands ttyto display the actual terminal currently mapped, such as: /dev/tty1or /dev/pts/0etc.

 

2.3 Virtual Console

/dev/ttynare process virtual consoles, they share the same real physical console.

On PCthe Internet, the user can use the Ctrl + Alt + Fnswitch, which corresponds to the virtual console tty1~n, where: /dev/tty1represents the first virtual console; when using Ctrl + ALT + F2 to switch, the virtual console of the system is /dev/tty2, and the current console ( /dev/tty) points to/dev/tty2

What is more special is /dev/tty0that it represents the current virtual console , which is actually an alias of the currently used virtual console. Therefore, no matter which virtual console is currently in use (note: this is a virtual console, excluding pseudo-terminals), system information will be relocated to /dev/tty0it.

Only the system or superuser rootcan /dev/tty0write to it. tty0It is automatically opened by the system, but it is not used for user login

 

3. Pseudo terminal

Pseudo-terminal (Pseudo Terminal)is the development of terminal. It is mostly used to simulate terminal programs and is (telnet、ssh、xterm等)a console device created after remote login.

It is a pair of logical terminal devices (that is, masterand slavedevices, masterthe operation of the pair will be reflected slaveon it).

Simply put, the master terminal is connected to the remote protocol processing process of the user space sshd, telnetdand the slave terminal is shellconnected to the actual process of the user space.

 

4. Serial terminal

A serial port terminal (Serial Port Terminal)is a terminal device connected using a computer's serial port. The computer sees each serial port as a character device. So the device names corresponding to these serial ports are /dev/ttyS0、/dev/ttyS1etc., and the device numbers are (4, 0), (4, 1) etc.

To send data to a port, you can redirect standard output to these special file names on the command line.

We can type at the command line prompt: echo "tekkaman" > /dev/ttyS1will send "tekkaman" to the device connected to the ttyS1 (COM2) port.

After kernel 2.6, some Samsung chips name the serial terminal device node as ttySACn .

TI's Omap series chips start from 2.6.37, and the UART device that comes with the chip starts to use the proprietary omap -uart driver , so the device node is named ttyOn to distinguish it from the device name "ttySn" when using the 8250 driver.

img

 

5. Other types

There are also many other types of terminal device special files for many different character devices, such as /dev/ttyInterminal devices for ISDN devices.

img

Like + follow, never get lost

img

Guess you like

Origin blog.csdn.net/dong__ge/article/details/128541977