开发者

Where does printk() print to?

开发者 https://www.devze.com 2023-01-22 02:22 出处:网络
Just a quick question on printk() function at 开发者_JS百科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)

Just a quick question on printk() function at 开发者_JS百科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)

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!


dmesg should display printk messages.


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


The printk(9) man page has a very small 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).


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 klogd for more detains and options.

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

#!/bin/bash

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

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

        done
        echo "done"

        if [ $1 ]
        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


Look for /dev/kmsg on your system.

0

精彩评论

暂无评论...
验证码 换一张
取 消