我正在加载一个简单的内核模块,它有一个init和一个退出函数,每个模块都显示一条消息。我使用日志级别的KERN_ALERT来显示消息,问题是退出消息首先显示,然后显示Init消息。
#include <linux/init.h>
#include <linux/module.h>
static int my_init(void){
printk(KERN_ALERT "Hello Kernel");
return 0;
}
static void my_exit(void){
printk(KERN_ALERT "bye-bye");
}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");我得到的信息是,
[ 6310.329500] bye-bye
[ 6324.158871] Hello Kernel他们有什么理由支持这个倒转的秩序,我错过了吗?
发布于 2014-07-14 18:13:36
延迟是由于我对消息设置的优先级。优先级的定义如下。
#define KERN_EMERG "<0>" /* system is unusable*/
#define KERN_ALERT "<1>" /* action must be taken immediately*/
#define KERN_CRIT "<2>" /* critical conditions*/
#define KERN_ERR "<3>" /* error conditions*/
#define KERN_WARNING "<4>" /* warning conditions*/
#define KERN_NOTICE "<5>" /* normal but significant condition*/
#define KERN_INFO "<6>" /* informational*/
#define KERN_DEBUG "<7>" /* debug-level messages*/默认编号为4,这允许控制台仅在KERN_WARNING中显示消息。这可能是我无法看到登录在KERN_INFO级别的原因。
发布于 2014-06-30 04:22:51
内核模块没有问题。我建议添加'\n'来刷新缓冲区。你可以得到适当的输出。
printk(KERN_ALERT "Hello Kernel \n");
|
|
V
For flushing buffer.注意::通过dmesg -c清除内核消息,并建议对输出进行双重检查。
发布于 2014-06-30 05:41:36
始终在printk末尾使用\n进行适当的刷新,其他明智的方法是缓冲这些消息和c
https://stackoverflow.com/questions/24469938
复制相似问题