What is the difference between console, tty and tty0 under linux!

1. Serial Port Terminal (/dev/ttySn) Serial Port Terminal (Serial Port Terminal) is a terminal device that uses a computer serial port to connect. The computer treats each serial port as a character device. For a while, these serial port devices were often referred to as terminal devices, because at that time their biggest use was to connect to 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 (4,0), ( 4, 1), etc., respectively correspond to COM1, COM2, etc. under the DOS system. If you want to send data to a port, you can redirect the standard output to these special file names on the command line. For example, typing at the command line prompt: echo test> /dev/ttyS1 will send the word "test" to the device connected to the ttyS1 (COM2) port.
3. Control terminal (/dev/tty) If the current process has a controlling terminal (Controlling Terminal), then /dev/tty is the device special file of the controlling 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 you log in, /dev/tty is the terminal you use, and the device number is (5,0). Use the command "tty" to check which actual terminal 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, the computer monitor is usually called the console terminal (Console). It emulates a type of Linux terminal (TERM=Linux), and some device special files are associated with it: tty0, tty1, tty2, etc. When you log in on the console, tty1 is used. When using Alt+[F1—F6] key combination, we can switch to tty2, tty3, etc. tty1–tty6, etc. are called virtual terminals, And tty0 is an alias of the virtual terminal currently in use, and the information generated by the system will be sent to this terminal (also called the console terminal at this time). Therefore, no matter which virtual terminal is currently being used, 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. The system outputs some information directly to the console. Currently, users are only allowed to log in to the console in single-user mode. 

tty:
If a process has a controlling terminal, /dev/tty is its controlling terminal. This thing is not fixed. Different programs open this device file may point to different terminals.
    #echo "test"> /dev/tty
    test
tty0:
    tty1-tty6, etc. are called virtual terminals, while tty0 is an alias of the virtual terminal currently in use, and the information generated by the system will be sent to
    the terminal. Therefore, no matter which virtual terminal is currently being used, the system information will be sent to the console terminal.
    #echo "test"> /dev/tty0
    test
    (Note: it seems to be in text mode)

/dev/tty is mainly for the process, and /dev/tty0 is for the entire system, that
is, the same It is a /dev/tty file. For different processes, its specific directions are different.
But no matter which process /dev/tty0 points to is the current virtual terminal.

I am in the tty1, tty2, tty3, tty4, tty5 console, and type echo hello >console or echo hello >tty or echo hello> tty0. Will they all output hello in the current console?

1 The current controlling terminal (/dev/tty)
/dev/tty refers to the current terminal, and the output here will only be displayed on the display of the current working terminal ; you can use the command "ps -ax" to view the process Which control terminal is connected. For the shell you log in, /dev/tty is the terminal you use, and the device number is (5,0).
Use the command "tty" to see which actual terminal device you correspond to . /dev/tty Some are similar to a connection to the actual terminal device used

2.
/dev/pts /dev/pts is the directory where the console device files created after remote login (telnet, ssh, etc.) are located. Since there may be thousands of users logging in, /dev/pts is actually generated dynamically, unlike other device files that are hard disk nodes that have been generated when the system is built.

3. Console terminal-system console (/dev/ console and /dev/tty*)
In the Linux system , the computer monitor is usually called the console terminal (Console). It emulates a type of Linux terminal (TERM=Linux), and there are some special device files associated with it. Related: tty0, tty1, tty2, etc. When you log in on the console, you use tty1. When you use the Alt+[ F1 —F6] key combination, we can switch to tty2, tty3, etc. tty1–tty6 It is called a virtual terminal , and tty0 is an alias of the virtual terminal currently in use, and the information generated by the system will be sent to the terminal. So no matter which virtual terminal is currently being used, System information will be sent to the console terminal.
You can log in to different virtual terminals, so that the system can have several different sessions at the same time. Only the system or the super user root can write to /dev/tty0 .

/dev # echo hello > console
hello
/dev # echo hello > tty
hello
/dev # echo hello > tty0
/dev # 
/dev # 

 

Guess you like

Origin blog.csdn.net/xiaolei251990/article/details/89743666