printk - showing in message log but not in termina

2019-07-18 19:07发布

I'm doing some kernel modification and am trying to get printk to output information back to the console. I pass any kernel log level with it and do not properly get any response back on the console for even the highest log levels.

I checked and the current log configuration for printk is 4 4 1 7.

It prints properly each time to logs. I can use dmesg | less and see it appended to the log. But I can't return it to console properly using printk.

I'm not sure that it matters but I use SSH to connect to a remote machine where the modified kernel exists.

I've tried SSH from gnome-terminal and from putty in Windows. Neither change a thing. Still shows printk in the server's logs, but not on my console.

Any way to get it to the console? What could be going wrong given that I've tried every log level and none work? THANKS!

6条回答
Deceive 欺骗
2楼-- · 2019-07-18 19:41

Just to make sure, you are in init level 3 (text mode) aren't you? If you have run startx and are working in graphical mode, you will not see stuff on the terminal.

查看更多
叛逆
3楼-- · 2019-07-18 19:45

I believe that prink only logs to the physical consoles, if you want to monitor the kernel output via arbitrary ttys, then you will need to use tail to monitor a file being written to by syslog, or an application such as xconsole which specifically monitors /dev/console for messages.

查看更多
仙女界的扛把子
4楼-- · 2019-07-18 19:45

Try using

dmesg -wH &

to force all your kernel messages, that are printed to dmesg (and also the virtual terminals like Ctrl+Alt+F1 , depending on your /proc/sys/kernel/printk log level and a level of your message), to also appear at your SSH or GUI console: Konsole, Terminal or whatever you are using! And, if you need to monitor only for the specific messages:

dmesg -wH | grep ERR &

I'm using it to monitor for the "ERROR" messages like

printk(KERN_EMERG "ERROR!\n");

that I printk from my driver

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-07-18 19:54

I believe some variants of syslog support this without doing kernel modifications, perhaps by logging to /dev/console. Is there any particular reason you're trying to modify the kernel to do this? I'd guess there's an easier way.

查看更多
看我几分像从前
6楼-- · 2019-07-18 19:57

Some distros patch out printk so it doesn't show up (Red Hat was first, Ubuntu does it too afaik) - you're probably hitting this.

查看更多
不美不萌又怎样
7楼-- · 2019-07-18 20:00

If it's for debugging - just tail the /var/log/messages. If you need stable output from your kernel module - create a char device or a file under /proc and have userland process read from there.

查看更多
登录 后发表回答