Linux terminal Introduction

Source: Internet
Author: User
Tags telnet program

Terminal Devices
A terminal (or TTY) device is a special character device. A terminal device is any device that can assume the role of a control terminal in a session, including the virtual console, serial interface (obsolete), and Pseudo Terminal (PTY ).

All terminal devices share a set of common functions: line discipline, which includes both general terminal line discipline and SLIP and PPP modes. The names of all terminal devices are similar. This part explains naming rules and various types of TTY (terminal) usage. It should be noted that these naming conventions contain several historical burdens. Some of them are exclusive to Linux, others are inherited from other systems, and others reflect that Linux has abandoned the habits of borrowing from other systems during its growth. The pound sign (#) indicates a decimal number without leading zero in the device name.

Virtual console and console device)
The virtual console is a terminal that is displayed in full screen on the system video monitor. The virtual console is named/dev/tty # Starting from/dev/tty1 #. /Dev/tty0 is the current virtual console. /Dev/tty0 is used to access the system video card on a machine that cannot use the frame buffer device (/dev/fb *). Do not use/dev/console for this purpose. /Dev/console is managed by the kernel and system messages will be sent here. In single-user mode, login must be allowed to use/dev/console.

Serial Interface
The "Serial Interface" here refers to the RS-232 serial interface and any device simulating this interface, whether in hardware (such as a modem) or in software (such as ISDN driver) simulation. Each serial interface in linux has two device names: the master device or the callin device, the alternate device, or the callout device. The device types are differentiated by uppercase and lowercase letters. For example, for any letter X, "tty" device name/dev/ttyX #, and "cu" device name is/dev/cux #. For historical reasons,/dev/ttyS # And/dev/ttyC # are equivalent to/dev/cua # And/dev/cub # respectively #. The names/dev/ttyQ # And/dev/cuq # are reserved for local use.

Pseudo Terminal (PTY)
Pseudo terminals are used to create login sessions or provide other functions, such as using TTY line discipline (including SLIP or PPP) to process arbitrary data generation. Each PTY has a master and a slave. According to the PTY naming scheme of System V/Unix98, all master nodes share the same/dev/ptmx device node (an unallocated PTY is automatically provided when the kernel is enabled ), all slave terminals are located in the/dev/pts directory named/dev/pts/# (the kernel will automatically generate and delete them as needed ).

Once the master is enabled, the corresponding slave device can be used in the same way as the TTY device. The master and slave devices are connected through the kernel, which is equivalent to two-way pipelines with TTY functions (pipe ).

========================================================== ========================================================== ========================
Tty is short for Teletype.
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, such as a telex typewriter (or ?), It is produced by Teletype. 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, because at that time they were used to connect 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 (), (), 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, if you type echo test>/dev/ttyS1 at the command line prompt, the word "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, for example,/dev/ptyp3 and/dev/ttyp3 (or/dev/pty/m3 and/dev/pty/s3 in the device file system ). They are not directly related to physical devices. If a program regards ttyp3 as a serial port device, its read/write operations on the port will be reflected in another logical terminal device pair (ttyp3 ). Ttyp3 is the logical device used by another program for read/write operations. In this way, two programs can communicate with each other through this logical device, and one of the programs using ttyp3 thinks they 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) (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 is passed to the getty program through m2 and s2, the getty program returns the "login:" string information to the network through s2, m2, and telnet. 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.
Before using device filesystem, HP-UX AIX and others used complicated naming methods to get a large number of special files for pseudo-terminal devices.

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, and 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 Linux terminal (TERM = Linux), and some special files of the device are associated with it: tty0, tty1, tty2, and so on. 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 is called a virtual terminal, while tty0 is an alias of the currently used 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.