我在 Ubuntu 10.04 机器上写了一个简单的 hello-world 模块。加载和卸载模块时,printk 应记录来自以下 hello_world 和 bye_world 函数的消息。
static int hello_world()
{
printk(KERN_INFO "Hello, beautiful world");
return 0;
}
static void bye_world()
{
printk(KERN_INFO "Good-bye kernel uncle");
}
module_init(hello_world);
module_exit(bye_world);
然而,当实际插入和删除 hello.ko 模块时,我看到终端上打印的消息(我将其重定向到当前终端)恰好是一个消息落后。
# rmmod hello.ko # Jul 8 16:34:02 panchavati kernel: [64599.954113] Hello, beautiful world # insmod hello.ko # Jul 8 16:34:57 panchavati kernel: [65456.367422] Good-bye kernel uncle
从 dmesg 输出中,我可以看到下一个消息条目(对应于 insmod)已经被记录,只是它还没有被打印出来。
chanakya@panchavati:~$ dmesg | tail -2 [65456.367422] Good-bye kernel uncle [65511.198299] Hello, beautiful world
条目 [65511.198299]
存在于内核日志中,但只打印了之前的条目 [65456.367422] Good-bye kernel uncle
。为什么会这样?
我早些时候认为/etc/syslog.conf 中使用的 '-' specifier 可能必须对此做些什么(它会阻止每次写入后同步),但删除它也不起作用。
最佳答案
您是否尝试过使用 tailf
(或 tail -f
)?它将在消息到达时将其打印出来。例如:
tailf /var/log/messages
关于linux - 为什么 syslog 文件中的内核日志消息(或那些重定向到终端的消息)正好落后一个 'message'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11382698/