The information which is printed by printk() can only be seen under Alt+Ctrl+F1 ~ F7 console. These consoles are very inconvenient for debugging since they can't roll back. I am using KDE desktop environment and console terminal, how could I redirect the printk() message to console?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Kernel oops Oops: 80000005 on arm embedded system
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
Use
to force all your kernel messages, that are printed to dmesg (and also the virtual terminals like Ctrl+Alt+F1 , depending on your /proc/sys/kernel/printk log level and a level of your message), to also appear at your SSH or GUI console: Konsole, Terminal or whatever you are using! And, if you need to monitor only for the specific messages:
I'm using it to monitor for the "ERROR" messages like
that I printk from my driver
printk() is a function provided by the Linux kernel to print debug/information/error messages. Internally, the kernel maintains a circular buffer that is
__LOG_BUF_LEN
bytes long (depending on the configuration, it can range from 4KB to 1MB).There are 8 possible loglevels associated to messages and defined in linux/kernel.h:
KERN_EMERG
: Emergency (system is unusable)KERN_ALERT
: Serious problem (i.e. action must be taken immediately)KERN_CRIT
: Critical condition, usually related to hardware or software failureKERN_ERR
: Used for error conditions, usually related to hardware difficultiesKERN_WARNING
: Used to warn about problematic situations that are not seriousKERN_NOTICE
: Normal situations that require notificationKERN_INFO
: Informational messages; many drivers print information about the hardware foundKERN_DEBUG
: Used only for debuggingEach string represents a number ranging from 0 to 7, with smaller values representing higher priorities. The default log level is equal to the
DEFAULT_MESSAGE_LOGLEVEL
variable specified in kernel/printk/printk.c.How messages can be read from user-level depends both on the configuration of some user-level daemons (e.g., klogd and syslogd) and on the default loglevel. To answer your question, depending on your specific configuration, one or more of the following commands will allow you to read the output of printk:
dmesg
console command (usually, the preferred way for one-shot manual checking)tail -f /var/log/kern.log
command/proc/kmsg
(discouraged)Depending on your configuration, you may also want to change the default loglevel shown in console. Starting from klogd 2.1.31, the default loglevel can be changed by echoing into
/proc/sys/kernel/printk
. Examples:echo 5 > /proc/sys/kernel/printk
will display on console only messages with loglevel from 0 to 4echo 8 > /proc/sys/kernel/printk
will display on console messages with any loglevelThe syntax of printk is
kernel defines 8 log levels in the file printk.h
Each log level corresponds to a number and the lower the number higher the importance of the message.
The levels are useful in deciding what should be displayed to the user on the console and what should not be.
Every console has log level called as the the console log level and any message with a log level number lesser than the console log level gets displayed on the console, and other messages which have a log level number higher or equal to the console log level are logged in the kernel log(kernel buffer) which can be looked into using the command "dmesg".
The console loglevel can be found by looking into the file /proc/sys/kernel/printk
The first number in the output is the console log level, the second is the default log level, third is the minimum log level and fourth is the maximum log level.
Log level 4 corresponds to KERN_WARNING. Thus all the messages with log levels 3,2,1 and 0 will get displayed on the screen as well as logged and the messages with log level 4,5,6,7 only get logged and can be viewed using "dmesg".
The console log level can be changed by writing into the proc entry
Now the console log level is set to 6, which is KERN_INFO.
Here you want to print out every message so you should set your console level at highest number "8"
or