我是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!$$$$$
我真的不明白如何生成[]中的那些。有人可以给我一个提示吗?
答案 0 :(得分: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
(启用)。
答案 1 :(得分:0)
自系统启动以来,它们实际上是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