Drive Debug Print to proc virtual file 1

Source: Internet
Author: User
Tags dmesg

PRINTK will put the data in the kernel's 1 buffers, the other way to output information from the hardware, when we want to view the previous information can be used DMESG command to print out the information in the buffer. The DMESG command prints out the information from/proc/kmsg


Proc is a virtual file system

When the system starts,


There's mount-a in there. A means that all the file systems are hooked up.


All file systems in the file fstab, such as the proc file system mounted in the/proc directory


To view mounted file systems


The files inside the virtual file system proc are generated by the kernel, and the properties are read


You can use Cat/proc/kmsg to view kernel output information, and there will be a print level in front of each line of information



The use of cat/proc/kmsg there is no output information, it may be the problem of the read and write mechanism inside

Drivers inside are used PRINTK, assuming that the kernel printing information is very much, the driver to print the information separately to exist somewhere, do not want to be mixed with other things, you can imitate the construction of/proc/kmsg file, driver information printing to another buffer inside


PRINTK information in two ways, all the way there log_buf inside (can be read through/proc/kmsg, through the DMESG command to read the/proc/kmsg file), printed out. In the following: Define 1 buf such as mulog_buf, generate 1 files/proc/mymsg, read the file/proc/mymsg Bar information print out, drive MYPRINTK the information exists LOG_BUF


In the kernel of the FS directory under the proc, there are proc of various operating functions

Analyzing the PROC_MISC.C entry function

If the Config_printk,create_proc_entry function is configured to create 1 entries in the proc directory, the 1th parameter name is kmsg, the 2nd parameter is the attribute (read-only), and the 3rd parameter is the parent, which represents the proc root directory. The file_operation structure of this entry after it is created. When the application opens/proc/kmsg, Open,read,write uses the structure proc_kmsg_operation (file_operation) open,read,write


Search for other programs to call the Create_proc_entry function to see what files are included.

Ring Buffer

buf Array


printk.c inside

The head is the same as the tail (read and write position ) is empty, when there is data, the end of the unequal will wake up


The data is read from the ring buffer after wake, and then returned to the user by calling _put_user








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.