Article Directory
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 TTY
it, which is a general term for various (physical/virtual) terminals!
Linux
The 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 Linux
commonly used terminals and Linux TTY Framework
lay the foundation for learning!
2. Console terminal
Console terminals include: system console, current console, and virtual console.
2.1 System Console
The system console, which is Linux
below 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
.
console
There 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=ttyS1
point the console terminal to thettyS1
serial 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/tty
is the device file of the current process console .
For the login Shell
, /dev/tty
it is the console you are using, and the device number (5, 0) /dev/tty
will be mapped to the current device (you can use the command tty
to check which actual physical console device it corresponds to), and /dev/tty
the output will only be displayed in the current on the working terminal.
You can enter commands
tty
to display the actual terminal currently mapped, such as:/dev/tty1
or/dev/pts/0
etc.
2.3 Virtual Console
/dev/ttyn
are process virtual consoles, they share the same real physical console.
On PC
the Internet, the user can use the Ctrl + Alt + Fn
switch, which corresponds to the virtual console tty1~n
, where: /dev/tty1
represents 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/tty0
that 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/tty0
it.
Only the system or superuser root
can /dev/tty0
write to it. tty0
It 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, master
and slave
devices, master
the operation of the pair will be reflected slave
on it).
Simply put, the master terminal is connected to the remote protocol processing process of the user space
sshd
,telnetd
and the slave terminal isshell
connected 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/ttyS1
etc., 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/ttyS1
will 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.
5. Other types
There are also many other types of terminal device special files for many different character devices, such as /dev/ttyIn
terminal devices for ISDN devices.
Like + follow, never get lost