Http://blog.sina.com.cn/s/blog_6151984a0100ejfg.html /Sbin/Getty-l 38400 ttys0 VT100 Command used: Tty view which terminal to use Who views logged-on users W. View login users Echo "ABC">/dev/pts /* Echo "123">/dev/ttyama0 information transmission between different terminals When you run a program, the process will definitely correspond to a terminal, and the printf print information will appear on the terminal. When the program enters the kernel state (such as calling the driver ), printk prints information on the kernel terminal (hisilicon set-top box console = ttyama0 = serial port 0) Console = tty0 = tty1 ~ on PC ~ 6,/dev/tty = 'tty '= This console On the embedded machine console = ttys0 = serial port Echo "Haha">/dev/console output to the system console (console = ttys0, indicating that the system console is a serial port) Echo "Haha">/dev/tty is equal to the following Echo "Haha"> 'tty 'is output to this console (the TTY command is output to this console) Console includes: TTY and framebuffer Tty includes: TTYs *, tty *, And/dev/pts) Framebuffer includes LCD, VGA, and other devices. ========================================================== ========================================== 1. Serial Port Terminal The device name is/dev/ttysn (here n is numbers 0, 1, 2, 3 .....) 2. Pseudo Terminal (Pty) A Pseudo Terminal is a terminal formed by remote logon. Its console control file is in the/dev/PTS directory. The name is from 0, 1, 2, 3, 4 ...... Continue later You can echo "okok">/dev/pts/0 to check the effect 3. virtual console (Terminal) The virtual console is the console automatically started after the machine is started normally. You can use CTRL + ALT + F1 to CTRL + ALT + F6 to switch (only 6 virtual consoles are enabled by default) The device control files are/dev/tty1,/dev/tty2,/dev/tty3,/dev/tty4,/dev/tty5, And/dev/tty6. Also,/dev/tty0 corresponds to the current virtual console (terminal) 4,/dev/tty This refers to the control terminal of the current process. It can be seen as a link to the control terminal. Run the TTY command to view the current shell control terminal. 5,/dev/console This is the system console A lot of system information will be hit here Generally /Dev/Console indicates/dev/tty0. ========================================================== ========================================== (1)/dev/console is a system control terminal. All system error messages are output here. (2)/dev/tty (N or Sn) is the process console. If such a file is opened in the process and the file is not the control terminal of other processes, The file is the control terminal of the process. In this case, a piece of data in the printf process is output here. (3) on the local machine, users can use Alt + F1 ~ The FN switch console seems to have multiple screens. This virtual console corresponds to the tty1 ~ N But in fact, the machine has only one screen, that is, the screen we see, corresponding to the console. It can be understood that the console points to the activated tty (not in details, tty0 is the activated tty, Or, accurately, the activated TTY ). To display the output to the console ). Historically, the console refers to the screen keyboard of the host, while the TTY refers to the console (only including the screen and keyboard) in other locations connected by a cable) # Include <fcntl. h> # Include <unistd. h> Int main () { Int FD; FD = open ("/dev/tty2", o_wronly | o_noctty ); Write (FD, "Hello tty2 \ n", 10 ); Return 0; } (4) A terminal is a type of terminal device. It has multiple types and generally uses tty for short. Tty is short for teletype. Teletype is one of the earliest terminal devices, which is produced by teletype, like a telex typewriter (OR & #61514. The device name is stored in the special file directory/dev/. The special device files on the terminal generally include the following types: 1. Serial Port Terminal (/dev/ttysn) The serial port terminal (serial port terminal) is a terminal device connected by a computer serial port. The computer regards each serial port as a character device. For some time, these serial port devices are usually called terminal devices, At that time, it was used to connect the terminal. 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 (), (), and so on, respectively, corresponding to COM1 and com2 in the DOS system. To send data to a port, You can redirect the standard output to these special file names on the command line. For example, type: Echo test>/dev/ttys1 The "test" is sent to the device connected to the ttys1 (com2) port.
2. Pseudo Terminal (/dev/PtY /)
Pseudo Terminal is a pair of logical terminal devices, such as/dev/ptyp3 and/dev/ttyp3 (or in the file system of the device ). /Dev/PtY/m3 and/dev/PtY/S3 ).
They are not directly related to physical devices. If a program regards ttyp3 as a serial port device, The read/write operations on the port are reflected on the other side of the logical terminal device pair (ttyp3), while ttyp3 is another program for reading The logical device for write operations. In this way, two programs can communicate with each other through this logical device, while one of the programs that use ttyp3 recognizes You are communicating with a serial port. This is like pipeline operations between logical device pairs. For ttyp3 (S3), any program designed to use a serial port device can use this logical device. However, for programs that use ptyp3, A dedicated design is required to use the ptyp3 (m3) logical device. For example, if someone uses a telnet program to connect to your computer online, the telnet program may start to connect to the device ptyp2 (m2) (On A Pseudo Terminal port ). At this time, a Getty program should run on the corresponding ttyp2 (S2) port. When Telnet obtains a character from the remote end, the character will be passed to the Getty program through m2 and S2, And the Getty program will pass through S2 and m2 Returns "login:" string information to the network with the telnet program. In this way, the login program communicates with the telnet program through a "Pseudo Terminal. By using appropriate software, you can connect two or more Pseudo Terminal devices to the same physical serial port. 3. control terminal (/dev/tty)
If the current process has a control terminal (controlling terminal),/dev/tty is the device special file of the control terminal of the current process. You can run the "PS-Ax" command to check which control terminal the process is connected. For the shell you log on to,/dev/tty is the terminal you are using, The device number is (5, 0 ). Run the "tty" command to check which actual terminal device it corresponds. /Dev/tty is similar to a connection to the actually used terminal device.
4. Console terminal (/dev/ttyn,/dev/console) In Unix systems, a computer monitor is usually called a console ). It simulates a terminal of the Linux type. (Term = Linux), and some special device files are associated with them: tty0, tty1, and tty2. When you log on to the console, tty1 is used. With Alt + [F1-F6] keys, we can switch to tty2, tty3 and so on. Tty1-tty6 and so on are called virtual terminals, whileTty0 is an alias for the current virtual terminal.The information generated by the system is sent to the terminal. Therefore, no matter which virtual terminal is being used, the system information will be sent to the console terminal. You can log on to different virtual terminals, so that the system can have several different sessions at the same time. Only the system or Super User Root can write data to/dev/tty0,
5. Other Types There are many other types of special files for terminal devices for many different character devices. For example,/dev/ttyin terminal devices for ISDN devices. I will not repeat it here |