First, distinguish/dev/tty,/dev/console,/dev/pts,/DEV/TTYN/DEV/TTYSN
Typically, the console (console) we see under Linux is done by several devices. Is/dev/ttyn. You typically use a hotkey alt+fn to switch between these virtual terminals. All of these TTY devices are matched by linux/drivers/char/console.c and vt.c.
Control Terminal/dev/tty refers to the current terminal, output to this content will only be displayed on the current work of the terminal monitor, if the current process has control terminal (controlling Terminal), then/dev/tty is the current process of the control terminal device special files. You can use the command "Ps–ax" to see which control terminal the process is connected to. For your login Shell,/dev/tty is the terminal you are using, the device number is (5,0). Use the command "TTY" to see exactly which actual terminal device it corresponds to. The/dev/tty is somewhat similar to a connection to the actual device being used. This terminal file can be shared by each user console terminal/dev/ttyn N (0 to 6) Tty1,tty2 is a different virtual terminal (dummy console)./dev/console is Tty0, Tty0 is an alias to the virtual terminal that is activated by the current virtual terminal, and the information generated by the system is sent to the terminal, in fact the machine has only one screen, which is the screen we see, which can be understood as the console pointing to the active TTY, Exactly the active TTY will display the output to the console. Historically, the console refers to the on-screen keyboard of the host itself, while TTY refers to the console (only the screen and keyboard) of the other locations where the cable is linked. Tty0 is automatically opened by the system, but not for user login
Pseudo terminal/dev/pts is the directory where console device files are created after remote login (TELNET,SSH, etc.). Because there may be a good thousands of users logged in,/dev/pts is actually dynamically generated, unlike other device files that have been generated when the system was built (if DEVFS is not used). The first user logs in, console's device files are/dev/pts/0, the second is/DEV/PTS/1, and so on. Here 0, 1, 2, 3 are not specific standard input or output, but the entire console. You can try Echo
"AAAAAA" >/dev/pts0, 1, 2 .....
Serial port terminal (/DEV/TTYSN)
A serial port terminal (serial port Terminal) is a terminal device that is connected using a computer serial port. The computer regards each serial port as a character device. For a while these serial port devices are often referred to as terminal equipment, because at that time its maximum use is to connect terminals. The device names corresponding to these serial ports are/dev/tts/0 (or/DEV/TTYS0),/dev/tts/1 (or/dev
/TTYS1), equipment numbers are (4,0), (4,1), respectively, corresponding to the DOS system under the COM1, COM2 and so on. To send data to a port, you can redirect standard output from the command line to these
On a special file name. For example, at the command prompt, type: Echo Test >/dev/ttys1 sends the word "test" to the device attached to the ttyS1 (COM2) port.
Ii. using Ioct1 function to manipulate virtual terminal equipment files
Virtual terminal, also called Virtual screen, its English name is Virtual terminal, abbreviated as VT or VT. Virtual terminals are widely used in Unix system users. It solves the limitation of the single interface of the console, enabling the user to enable another interface to do another work while protecting the current interface. We can use the system modulation provided by the UNIX system to develop the virtual terminal program, and we can add it to our application. I have written the graphic software on the basis of this virtual terminal program, which can save and restore the previous interface. The Ioct1 function can be used to manipulate the virtual terminal equipment file to realize the interaction with the kernel of UNIX system and get the service we need. The specific form of using Ioct1 is as follows: int ioct1 (int filedes,int request,.../* Parameters * * *) Filedes for the open virtual Terminal device file descriptor, request for the requested service, subsequent parameters can be of various data types, Depending on the circumstances. Used in Ioct1 calls related to virtual terminals
The main number of request values are as follows:
Vt_openqry find a virtual terminal that can be exploited. The parameter used to ioct1 the system call is a pointer to a long integer. The value of the long integer is placed as the ordinal number of the first available virtual terminal on which no process is open. If there is no available virtual terminal, the value of the long integer is set to-1. Vt_getmode gets the state in which the active virtual terminal is currently located. The parameter used to ioct1 the system call is a pointer to the VT_MODE structure. The structure vt-mode is defined as follows:
struct Vt-mode {
Char mode;/* VT Mode * *
Char waitv;/* if Set,hang on writes while not active *
Short relsig;/*signal to use for release request */
Short Acqsig; /*signal to use for display acquired * *
Short Frsig; /*not use Set to 0 * *
}
In structure Vt_mode, the value of the Mode field can be Vt_auto and vt_process, and their macros are defined as follows:
#define VT_AUTO 0x00/* Automatic switching *
#define VT_PROCESS 0x01/* Process Control switch * *
Vt_setmode sets the virtual terminal mode (automatic or Process Control). The parameter used to ioctl the system call is a pointer to a ″vt_mode″ structure (see vt_getmode for the structure definition).
Vt_getstate obtains status information for all virtual terminals. The parameter of the system call for IOCTL is a pointer to the VT_STAT structure, which is defined as follows:
struct Vt_stat {
vt*/of ushort v_active;/* activities
UShort v_signal;/* the signal to be sent (for Vt_sendsig) * *
UShort V_state; /*VT bit Masks (Vt_sendsig and vt_getstate) * *
}