Basic knowledge: Linux Terminal tty device driver

Source: Internet
Author: User
Tags telnet program
Article title: Basic Knowledge: Linux Terminal tty device driver. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In Linux, terminal devices are very important. without terminal devices, the system will not be able to provide feedback to users. Linux contains three types of terminal devices: Console, serial port, and pseudo terminal.

Section 14.1 describes the concepts and categories of terminal devices, Section 14.2 describes the framework structure of the Linux terminal device driver, and focuses on the tty_driver structure and its members. 14.3 ~ Section 14.5, based on Section 14.2, provides the loading/uninstallation functions and open () and close () functions for the driver modules of Linux terminals, data read/write process and programming method for tty device line settings. In Linux, the serial port driver fully follows the tty driver framework structure, but the underlying operations are re-encapsulated. Section 14.6 describes the Linux encapsulation of the serial port tty driver, section 14.7 describes how to implement the tty driver on the serial port. Based on the explanations in sections 14.8 and 14.6, Section 14.7 provides an example of the serial port tty driver design, that is, the S3C2410 integrated UART driver.

14.1 terminal devices

In a Linux system, a terminal is a variety of types, usually using tty for short. Tty is short for Teletype. Teletype is the first terminal device to appear. it is similar to a telex typewriter and is produced by Teletype. Linux contains the following types of terminal devices:

 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. The device names corresponding to these serial ports are/dev/ttyS0 (or/dev/tts/0),/dev/ttyS1 (or/dev/tts/1), etc, the device numbers are (), (), and so on.

You can redirect the standard output to the device file name corresponding to the port on the command line to send data through the port. for example, at the command line prompt, type: echo test>/dev/ttyS1 sends the word "test" to the device connected to the ttyS1 port.

  2. pseudo terminal (/dev/pty /)

Pseudo Terminal is a pair of logical Terminal devices, and there are pair of device files, such as/dev/ptyp3 and/dev/ttyp3, which are not directly related to actual physical devices. If a program regards ttyp3 as a serial port device, its read/write operations on the port will be reflected on the ptyp3 corresponding to the logical terminal device, ptyp3 is the logical device used by another program for read/write operations. In this way, the two programs can communicate with each other through this logical device. The program using ttyp3 will think that it is communicating with a serial port.

Take telnet as an example. if someone is using the telnet program to connect to the Linux system, the telnet program may start to connect to the ptyp2 device, and a getty program will run on the corresponding ttyp2 port. When telnet obtains a character from the remote end, the character is passed to the getty program through ptyp2 and ttyp2, while the getty program returns "login: "String information. In this way, the login program communicates with the telnet program through a pseudo terminal. By using appropriate software, two or more pseudo terminal devices can be connected to the same physical serial port.

 3. console terminal (/dev/ttyn,/dev/console)

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?" command? Ax to check which control terminal the process is connected to. use the "tty" command to check which actual terminal device it corresponds. /Dev/tty is similar to a connection to the actually used terminal device.

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 virtual terminal currently in use. 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. Users can log on to different virtual terminals, so that the system can have several different session periods at the same time. Only the system or super user root can write data to/dev/tty0.

 

[1] [2] Next page

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: info-contact@alibabacloud.com 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.