Linux 内核中的打印输出去哪里了?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4518420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:17:25  来源:igfitidea点击:

Where does output of print in kernel go?

linuxubuntulinux-kernelprintk

提问by apoorv020

I am debugging a driver for linux (specifically ubuntu server 9.04), and there are several printf statements in the code.

我正在调试一个linux驱动(特别是ubuntu server 9.04),代码中有几个printf语句。

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

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");
    ...

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).

在 kern.log 中,当我尝试覆盖文件 /proc/net/madwifi/ath1/fractel_config(当然时间不同)时,我看到以下消息。

[ 8671.924873] proc write 
[ 8671.924919] 

Any explainations?

有什么解释吗?

采纳答案by Blrfl

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/dmesgor /var/log/kernel) or to the system log via syslog(3). In the latter case, where the log entries end up will depend on the configuration of syslogd(8).

这取决于发行版,但许多用于klogd(8)从内核获取消息,并将它们记录到文件(有时/var/log/dmesg/var/log/kernel)或通过syslog(3). 在后一种情况下,日志条目的最终位置将取决于syslogd(8).

One note about the dmesgcommand: Kernel messages are stored in a circular buffer, so large amounts of output will be overwritten.

关于该dmesg命令的一个注意事项:内核消息存储在循环缓冲区中,因此大量输出将被覆盖。

回答by chris

You'll get the output with the command dmesg

您将使用命令获得输出 dmesg

回答by Eric Seppanen

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.

您可以尝试比 KERN_DEBUG 更高的级别,例如 KERN_INFO。根据您的配置,最低优先级的消息可能不会显示。

回答by ctuffli

Many times KERN_DEBUGlevel 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:

多次KERN_DEBUG过滤级别消息,您需要显式增加日志记录级别。您可以通过检查来了解系统默认值是什么/proc/sys/kernel/printk。例如,在我的系统上:

# cat /proc/sys/kernel/printk
4       4       1       7

the first number shows the console log level is KERN_WARNING(see proc(5)man pages for more information). This means KERN_NOTICE, KERN_INFO, and KERN_DEBUGmessages will be filtered from the console. To increase the logging level or verbosity, use dmesg

第一个数字显示控制台日志级别是KERN_WARNING(有关更多信息,请参阅proc(5)手册页)。这意味着KERN_NOTICEKERN_INFOKERN_DEBUG消息将从控制台中过滤掉。要提高日志记录级别或详细程度,请使用dmesg

$ sudo dmesg -n 7
$ cat /proc/sys/kernel/printk
7       4       1       7

Here, setting the level to 7 (KERN_DEBUG) will allow all levels of messages to appear on the console. To automate this, add loglevel=Nto the kernel boot parameters where N is the log level you want going to the console or ignore_loglevelto print all kernel messages to the console.

在这里,将级别设置为 7 ( KERN_DEBUG) 将允许所有级别的消息显示在控制台上。要自动执行此操作,请将loglevel=N添加到内核​​引导参数,其中 N 是您想要进入控制台或ignore_loglevel将所有内核消息打印到控制台的日志级别。

回答by Abhisheietk

dmesgoutputs all the messages from the kernel. Finding your desired messages would be difficult. Better use dmesgand grepcombination and use a driver specific label in all your printkmessages. That will ease in eliminating all the unwanted messages.

dmesg输出来自内核的所有消息。找到您想要的消息会很困难。最好使用dmesggrep组合,并在所有printk消息中使用特定于驱动程序的标签。这将有助于消除所有不需要的消息。

printk("test: hello world")

dmesg | grep test

回答by Vectorio

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.

我在 Ubuntu 11.10 和 10.04 LTS 上遇到了这个问题,在之前我编辑了 /etc/rsyslog.d/50-default.conf,然后使用“sudo service rsyslog restart”重新启动了 rsyslog 以重新启动 rsyslogd。然后它起作用了。

Note that Ubuntu uses *r*syslogd, not syslogd.

请注意,Ubuntu 使用 * r*syslogd,而不是 syslogd。

回答by Thiyagarajan

In centos (Atleast in centos 6.6) the output will be in /var/log/messages

在centos中(至少在centos 6.6中)输出将在/var/log/messages中