【问题标题】:linux kernel printk outputlinux内核printk输出
【发布时间】:2013-05-27 02:35:44
【问题描述】:

我是 Linux 内核开发的新手,当我尝试通过在 timekeep.c 文件中添加 printk 函数来修改系统调用函数时,比如

 printk("BEGIN!$$$$$\n");

dmesg 实用程序为我提供如下输出:

[   75.919335] BEGIN!$$$$$
[   75.919337] BEGIN!$$$$$
[   75.919340] BEGIN!$$$$$
[   75.919343] BEGIN!$$$$$
[   75.919347] BEGIN!$$$$$
[   75.919349] BEGIN!$$$$$
[   75.919353] BEGIN!$$$$$
[   75.919355] BEGIN!$$$$$
[   75.919358] BEGIN!$$$$$
[   75.919361] BEGIN!$$$$$
[   75.919364] BEGIN!$$$$$
[   75.919367] BEGIN!$$$$$
[   75.919370] BEGIN!$$$$$
[   75.919374] BEGIN!$$$$$

我真的不明白 [] 中的那些是如何生成的。有人可以给我一个提示吗?

【问题讨论】:

  • 您忘记了日志级别前缀:printk(KERN_DEBUG "BEGIN!"\n");

标签: linux kernel output printk


【解决方案1】:

您的内核启用了 CONFIG_PRINTK_TIME 选项。此选项负责printk() 消息之前的此时间戳字段。从内核配置选项

 "Selecting this option causes time stamps of the `printk()` messages to be
  added to the output of the `syslog()` system call and at the console."

来源:https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/lib/Kconfig.debug#n2

此选项可在内核配置时通过“Kernel Hacking”配置字段进行配置。您可以通过内核命令行参数启用/禁用它:printk.time=0(禁用)或printk.time=1(启用)。

【讨论】:

    【解决方案2】:

    它们实际上是自系统启动后以秒为单位的 dmesg 时间戳。

    您可以放心地忽略它们,除非您实际上是在寻找时间问题(例如驾驶员需要 30 秒才能完成本应更快的事情)。

    如果您想要更易读的格式,可以使用dmesg -T,但会丢失一些精度。

    pax> dmesg -T | tail -5l
    
    [Mon May 27 09:08:58 2013] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
    [Mon May 27 09:09:00 2013] usblp0: removed
    [Mon May 27 09:09:00 2013] usblp0: USB Bidirectional printer dev 3 if 0 alt 0 proto 2 vid 0x03F0 pid 0x3A02
    [Mon May 27 09:09:09 2013] eth0: no IPv6 routers present
    [Mon May 27 10:09:59 2013] usblp0: removed
    

    您也可以使用dmesg -t 将它们完全删除,但您将丢失所有时间信息。

    pax> dmesg -t | tail -5l
    
    ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
    usblp0: removed
    usblp0: USB Bidirectional printer dev 3 if 0 alt 0 proto 2 vid 0x03F0 pid 0x3A02
    eth0: no IPv6 routers present
    usblp0: removed
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 2014-12-22
      相关资源
      最近更新 更多