Where does output of print in kernel go?

前端 未结 7 899
再見小時候
再見小時候 2020-12-14 08:23

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 statem

相关标签:
7条回答
  • 2020-12-14 08:55

    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:

    # 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_DEBUG messages will be filtered from the console. To increase the logging level or verbosity, use 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=N to the kernel boot parameters where N is the log level you want going to the console or ignore_loglevel to print all kernel messages to the console.

    0 讨论(0)
  • 2020-12-14 08:56

    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.

    0 讨论(0)
  • 2020-12-14 09:14

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

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

    0 讨论(0)
  • 2020-12-14 09:15

    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.

    printk("test: hello world")
    
    dmesg | grep test
    
    0 讨论(0)
  • 2020-12-14 09:16

    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.

    0 讨论(0)
  • 2020-12-14 09:18

    You'll get the output with the command dmesg

    0 讨论(0)
提交回复
热议问题