Reputation: 43
According to manual page it told that if priority of message's log level is higher than default set log level then it will be printed on terminal. But when I had used sentence like
printk(KERN_ALERT " MESSAGE ")
I am facing problem to print message on terminal. Because the default priority is set to 4 and KERN_ALERT
has priority 1
, which is higher.
So, how can I print message on terminal?
Upvotes: 3
Views: 8873
Reputation: 1
I faced same problem initially developing skeleton drivers on host system. every time I had to check with "dmesg" command.
I have to edit /proc/sys/kernel/printk .
For getting message on Terminal with window manager such ad KED and Gnome run "tail -f /var/log/kern.log &" to get messages on terminal.
It helped me in Ubuntu system. Hope it will help :)
Upvotes: 0
Reputation: 47583
I know that this doesn't exactly answer your question, but like I said in the comments, making printk
log to the console is generally not a good idea. This is an alternative I suggest that should well enough serve your purpose.
Since you want to use it for debug purposes, you could simply open a new terminal and execute the following command:
tail -f /var/log/messages
or
tail -f /var/log/dmesg
or the like. tail -f
would print the last messages in the file, but would keep waiting for updates. As soon as there are more lines written in the file, tail -f
would write them to console for you.
Regardless of whether you use this method or directly print to console, you may also be interested in defining a macro that calls printk
and in debug mode would also put a small msleep
after to make sure the log makes it to the screen, in case of crashes. This is done like this:
set_current_state(TASK_INTERRUPTIBLE);
msleep(/* amount in milliseconds */);
Upvotes: 2
Reputation: 3892
It should print messages to the console, not to the terminal. Sometimes the console and the terminal seems the same, but it is not. Edit /proc/sys/kernel/printk to set up the lowest priority to print in console
Upvotes: 3