Linux printk() 打印到哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4036624/
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-04 23:48:58  来源:igfitidea点击:

Where does printk() print to?

linuxdebugginglinux-kernel

提问by molleman

Just a quick question on printk() function at the kernel level, if I call this where will the message be printed to?(I'm using Ubuntu on i386 arch with the latest kernel download)

只是一个关于内核级别的 printk() 函数的快速问题,如果我调用它,消息将打印到哪里?(我在 i386 arch 上使用 Ubuntu 并下载了最新的内核)

can't find it anywhere,

到处都找不到,

If someone could also point me in the right direction for some sort of manual for the printk() function it would be great!

如果有人也可以为我指明正确的方向,为 printk() 函数提供某种手册,那就太好了!

采纳答案by Alan Haggai Alavi

dmesgshould display printkmessages.

dmesg应该显示printk消息。

回答by Ignacio Vazquez-Abrams

The printk(9)man page has a verysmall bit of information on it. In short, it gets sent to the log buffer, where a syslog daemon can pick it up and handle it. It also gets sent to the console if its loglevel is high enough (see dmesg(1)for that bit).

printk(9)手册页有一个非常的上信息的小一点。简而言之,它被发送到日志缓冲区,在那里 syslog 守护程序可以拾取并处理它。如果它的日志级别足够高,它也会被发送到控制台(请参阅dmesg(1)该位)。

回答by zwol

printkmessages go to the kernel log message buffer, which can be exposed in a variety of ways depending on system configuration. The shell command dmesgwill show them, and they should also be being copied to files in /var/logby the syslogdaemon. It's possible to get them logged to a serial console or a text-mode virtual terminal, but I don't remember how offhand.

printk消息进入内核日志消息缓冲区,可以根据系统配置以多种方式公开。shell命令dmesg将显示他们,而他们也应该被复制到文件/var/logsyslog守护进程。可以将它们记录到串行控制台或文本模式虚拟终端,但我不记得是多么随意。

回答by gsbabil

If you have put some printk()statements in the kernel module to debug and trying to capture the outputs as they are printk'ed, what you are looking for is klogd. Perform a man klogdfor more detains and options.

如果您printk()在内核模块中放置了一些语句以进行调试并尝试在打印输出时捕获输出,那么您正在寻找的是klogd. 执行 aman klogd以获取更多拘留和选项。

Here's a wrapper script for klogdthat I coded a while back to ease some quick debugging pain:

klogd是我编码的一个包装脚本,以减轻一些快速调试的痛苦:

#!/bin/bash

function bashtrap()
{
        echo
        echo -n "[+] stopping klogd ... "
        pids=`ps aux | grep klogd | awk '{print }'`

        for pid in $pids
        do    
                kill SIGTERM $pid 2> /dev/null

        done
        echo "done"

        if [  ]
        then
                exit;
        fi  
}

sync
bashtrap

klogd -x -f - -n -c 8 2>&1 1 | tee klog.txt & klog_pid=$!;

echo "[+] klogd started"
echo "[+] press ctrl+c to exit ... $klog_pid"

sync
trap "bashtrap 1" SIGINT

while [ 1 ]
do
        sleep 3
        echo -n "."
done

ps aux | grep klogd

回答by ichabod

Look for /dev/kmsgon your system.

/dev/kmsg在您的系统上查找。