【问题标题】:Why are kernel log messages in the syslog file (or those redirected to terminal) exactly one 'message' behind?为什么 syslog 文件中的内核日志消息(或重定向到终端的消息)恰好落后一个“消息”?
【发布时间】:2012-07-08 11:16:34
【问题描述】:

我在 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 可能必须对此做一些事情(它会阻止每次写入后的同步),但删除它也不起作用。

【问题讨论】:

    标签: linux linux-kernel syslog


    【解决方案1】:

    您是否尝试过使用tailf(或tail -f)?它会在消息到达时打印出来。例如:

        tailf /var/log/messages
    

    【讨论】:

      【解决方案2】:

      尝试用换行符(“\n”)结束你的字符串。

      【讨论】:

        猜你喜欢
        • 2019-09-27
        • 2017-05-31
        • 2011-09-06
        • 2020-12-28
        • 1970-01-01
        • 2016-12-13
        • 1970-01-01
        • 2015-01-06
        • 1970-01-01
        相关资源
        最近更新 更多