内核中 print 的输出去了哪里?
我正在调试linux(特别是ubuntu服务器9.04)的驱动程序,代码中有几个printf语句。
我在哪里可以查看这些语句的输出?
EDIT1:我想做的是使用 proc 文件系统写入内核。 打印代码
static int proc_fractel_config_write(struct file *file, const char *argbuf, unsigned long count, void *data)
{
printk(KERN_DEBUG "writing fractel config\n");
...
在 kern.log 中,当我尝试覆盖文件 /proc/net/madwifi/ath1/fractel_config (当然时间不同)时,我看到以下消息。
[ 8671.924873] proc write
[ 8671.924919]
有什么解释吗?
I am debugging a driver for linux (specifically ubuntu server 9.04), and there are several printf statements in the code.
Where can I view the output of these statements?
EDIT1: What i'm trying to do is write to kernel using the proc file-system.
The print code is
static int proc_fractel_config_write(struct file *file, const char *argbuf, unsigned long count, void *data)
{
printk(KERN_DEBUG "writing fractel config\n");
...
In kern.log, I see the following message when i try to overwrite the file /proc/net/madwifi/ath1/fractel_config (with varying time of course).
[ 8671.924873] proc write
[ 8671.924919]
Any explainations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
很多时候
KERN_DEBUG
级别的消息会被过滤,您需要显式提高日志记录级别。您可以通过检查 /proc/sys/kernel/printk 来查看系统默认值。例如,在我的系统上:第一个数字显示控制台日志级别为
KERN_WARNING
(请参阅 proc(5) 手册页了解更多信息)。这意味着KERN_NOTICE
、KERN_INFO
和KERN_DEBUG
消息将从控制台中过滤掉。要提高日志记录级别或详细程度,请使用dmesg
此处,将级别设置为 7 (
KERN_DEBUG
) 将允许所有级别的消息显示在控制台上。要自动执行此操作,请将loglevel=
N 添加到内核启动参数,其中 N 是您想要转到控制台或ignore_loglevel
打印的日志级别发送到控制台的所有内核消息。Many times
KERN_DEBUG
level messages are filtered and you need to explicitly increase the logging level. You can see what the system defaults are by examining/proc/sys/kernel/printk
. For example, on my system:the first number shows the console log level is
KERN_WARNING
(see proc(5) man pages for more information). This meansKERN_NOTICE
,KERN_INFO
, andKERN_DEBUG
messages will be filtered from the console. To increase the logging level or verbosity, usedmesg
Here, setting the level to 7 (
KERN_DEBUG
) will allow all levels of messages to appear on the console. To automate this, addloglevel=
N to the kernel boot parameters where N is the log level you want going to the console orignore_loglevel
to print all kernel messages to the console.这取决于发行版,但许多人使用
klogd(8)
从内核获取消息,并将它们记录到文件中(有时/var/log/dmesg
或/var/log/kernel
)或通过syslog(3)
到系统日志。在后一种情况下,日志条目的最终位置将取决于 syslogd(8) 的配置。关于 dmesg 命令的一点注意事项:内核消息存储在循环缓冲区中,因此大量输出将被覆盖。
It depends on the distribution, but many use
klogd(8)
to get the messages from the kernel and will either log them to a file (sometimes/var/log/dmesg
or/var/log/kernel
) or to the system log viasyslog(3)
. In the latter case, where the log entries end up will depend on the configuration ofsyslogd(8)
.One note about the
dmesg
command: Kernel messages are stored in a circular buffer, so large amounts of output will be overwritten.您将使用命令
dmesg
获得输出You'll get the output with the command
dmesg
dmesg 输出来自内核的所有消息。找到您想要的消息会很困难。最好使用 dmesg 和 grep 组合,并在所有
printk
消息中使用驱动程序特定标签。这将轻松消除所有不需要的消息。dmesg outputs all the messages from the kernel. Finding your desired messages would be difficult. Better use dmesg and grep combination and use a driver specific label in all your
printk
messages. That will ease in eliminating all the unwanted messages.我在 Ubuntu 11.10 和 10.04 LTS 上遇到了这个问题,在前者上我编辑了 /etc/rsyslog.d/50-default.conf,然后使用“sudo service rsyslog restart”重新启动 rsyslog 来重新启动 rsyslogd。然后就成功了。
请注意,Ubuntu 使用 *r*syslogd,而不是 syslogd。
I had this problem on Ubuntu 11.10 and 10.04 LTS, on the former I edited /etc/rsyslog.d/50-default.conf, then restarted rsyslog using "sudo service rsyslog restart" to restart rsyslogd. Then it worked.
Note that Ubuntu uses *r*syslogd, not syslogd.
您可以尝试比 KERN_DEBUG 更高的级别,例如 KERN_INFO。根据您的配置,可能不会显示优先级最低的消息。
You might try a higher level than KERN_DEBUG, for example KERN_INFO. Depending on your configuration the lowest priority messages might not be displayed.
在 centos 中(至少在 centos 6.6 中)输出将位于 /var/log/messages 中
In centos (Atleast in centos 6.6) the output will be in /var/log/messages