linux kprint messages on console

2019-09-01 02:19发布

问题:

In order to print this meesage on console, I killed klogd with kill -SIGKILL <pid>command and restarted klogd with klogd -s -c 2 I still don't see the message on console. What do I miss here? Thanks in advance.

printk(KERN_ALERT "Hello World\n");

回答1:

You have to make sure you're in full terminal mode( press Alt+Ctrl+f2 or f3) and not Graphical mode.

then check if the /proc/sys/kernel/printk is having right values

# cat /proc/sys/kernel/printk

4 4 1 7

my current setting are above. You can use echo 8 > /proc/sys/kernel/printk to print everything. for kern_alert 4 is enough.

for testing you can use below from full terminal mode.

#echo "<1>Writing critical printk messages from userspace" >/dev/kmsg

this will print to the terminal

http://elinux.org/Debugging_by_printing

kern_alert with print to current terminal while kern_emerg will print to all terminals.



回答2:

Also look at the level of priority within your syslog.conf (or equivalent) that tells what levels will be logged if your looking at /var/log/messages. Your settings are likely ...

#define KERN_EMERG   "<0>" /* system is unusable               */        
#define KERN_ALERT   "<1>" /* action must be taken immediately */
#define KERN_CRIT    "<2>" /* critical conditions              */
#define KERN_ERR     "<3>" /* error conditions                 */
#define KERN_WARNING "<4>" /* warning conditions               */
#define KERN_NOTICE  "<5>" /* normal but significant condition */
#define KERN_INFO    "<6>" /* informational                    */
#define KERN_DEBUG   "<7>" /* debug-level messages             */