The information printed in the driver development using the function PRINTK () can be viewed through DMESG
The ' DMESG ' command displays the ring buffer information for the Linux kernel, where we can obtain a large amount of system information, such as system architecture, CPU, mounted hardware, RAM, and many other operational levels. When the computer starts, the system kernel (the core part of the operating system) is loaded into memory. A lot of information is displayed during the loading process, in which we can see the hardware devices detected by the kernel.
Example of using the DMESG command
The ' DMESG ' command to diagnose a device failure is very important. When hardware is connected or disconnected with the help of the ' dmesg ' command, we can see the hardware detection or disconnection information. The ' DMESG ' command is available in most Linux and UNIX-based operating systems.
We can use such as ' more '. ' Tail ', ' less ' or ' grep ' word processing tool to handle the output of the ' DMESG ' command. Because the output of the DMESG log is not intended to be fully displayed on a single page, we use a pipe to send its output to the more or less command-page display.
Follow the ' head ' command after the ' DMESG ' command to display the starting lines, ' DMESG | The head-20′ command displays the first 20 lines that begin.
Follow the ' tail ' command after the ' DMESG ' command (' DMESG | Tail-20 ') to output the last 20 lines of the ' DMESG ' command, which is useful when you plug in a removable device.
Because the output of the ' DMESG ' command is too long, it is very difficult to search for a particular string. Therefore, it is necessary to filter out some log lines that contain strings such as ' USB ' DMA ' TTY ' memory '. The '-i ' option of the grep command indicates that the case is ignored.
grep -grep -grep -grep -I memory
We can use the following command to empty the DMESG log. This command empties the log in the DMESG ring buffer. However, you can still view the logs stored in the '/VAR/LOG/DMESG ' file. Any device you connect to will generate DMESG log output.
[Email protected] log]# dmesg-c
In some distributions, the command ' tail-f/VAR/LOG/DMESG ' can be used to monitor DMESG log output in real time. Watch-n 2 "DMESG | Tail-20 "represents the contents of a 2s periodic execution of quotes
" DMESG | tail-20 "