- Linux Device Driver Development Cookbook
- Rodolfo Giometti
- 376字
- 2021-06-24 13:54:13
Getting ready
Our ESPRESSObin is the system that generates kernel messages, so we need a connection to it. Through the serial console, these messages are automatically displayed as soon as they arrive, but if we are using an SSH connection, we can still display them by reading specific files, as with the following command:
# tail -f /var/log/kern.log
However, the serial console deserves a special note: in fact, in our example, the kernel messages will be automatically displayed on the serial console, if, and only if, the leftmost number, among the ones found inside the /proc/sys/kernel/printk file, happens to be greater than seven, as shown in the following:
# cat /proc/sys/kernel/printk
10 4 1 7
These magic numbers have a well-defined meaning; in particular, the first one represents the error message level that the kernel must show on the serial console. These levels are defined in the linux/include/linux/kern_levels.h file, as follows:
#define KERN_EMERG KERN_SOH "0" /* system is unusable */
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
#define KERN_CRIT KERN_SOH "2" /* critical conditions */
#define KERN_ERR KERN_SOH "3" /* error conditions */
#define KERN_WARNING KERN_SOH "4" /* warning conditions */
#define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
#define KERN_INFO KERN_SOH "6" /* informational */
#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
For example, if the contents of the preceding file were 4, as reported in the following, only messages having the KERN_EMERG, KERN_ALERT, KERN_CRIT, and KERN_ERR levels will be automatically displayed on the serial console:
# cat /proc/sys/kernel/printk
4 4 1 7
In order to allow all messages, a subset of them, or none to be displayed, we have to modify the leftmost number of the /proc/sys/kernel/printk file by using the echo command, as in the following example in which we act in such a way to completely disable the printing of all kernel messages. This is because no message can have a priority level greater than 0:
# echo 0 > /proc/sys/kernel/printk
Now that we know how to display kernel messages, we can try to perform some modifications to our kernel code in order to do some experimentation with kernel messages.
- 嵌入式Linux開(kāi)發(fā)技術(shù)
- Designing Purpose:Built Drones for Ardupilot Pixhawk 2.1
- 零起點(diǎn)學(xué)Linux系統(tǒng)管理
- 網(wǎng)絡(luò)操作系統(tǒng):Windows Server 2003管理與應(yīng)用
- 嵌入式Linux系統(tǒng)開(kāi)發(fā):基于Yocto Project
- 構(gòu)建可擴(kuò)展分布式系統(tǒng):方法與實(shí)踐
- 嵌入式操作系統(tǒng)(Linux篇)(微課版)
- Windows Phone 8 Application Development Essentials
- 無(wú)蘋(píng)果不生活 The New iPad隨身寶典
- 計(jì)算機(jī)系統(tǒng)的自主設(shè)計(jì)
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)(Windows 7+Office 2016)
- Social Data Visualization with HTML5 and JavaScript
- 精解Windows 10
- Agile IT Security Implementation Methodology
- 鴻蒙入門:HarmonyOS應(yīng)用開(kāi)發(fā)