Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kernel module: how to get console ouput?

I am writing a kernel module, and I want to be able to print something on the console output when loading it using insmod module.ko.

I tried using

printk(KERN_EMERG "test kernel emergency\n");

but nothing appears on my console. It does however appear in dmesg.

Extra info:
I am using an Intel x86 32 bit with linux-3.0.0

and cat /proc/sys/kernel/printk gives4 4 1 7

like image 583
Jens Nyman Avatar asked Feb 22 '12 12:02

Jens Nyman


2 Answers

1- make sure you're in full terminal mode( press Alt+Ctrl+f1)

2- instead of printk(KERN_EMERG "test kernel emergency\n"); try

printk(KERN_ALERT "test kernel alert\n");

like image 75
Varda Elentári Avatar answered Oct 15 '22 04:10

Varda Elentári


Jens,

printk ouputs are sent to kernel and collected by syslogd daemon. dmesg echoes the data collected by syslogd daemon.

This message may not be printed by your console (from where you called insmod) if you are using Graphical version of linux. I have tried this in ubuntu and it doesn't print the printk messages even if the log level is ALERT or EMERGENCY.

like image 29
Vinayak Kolagi Avatar answered Oct 15 '22 06:10

Vinayak Kolagi