Kernel module: how to get console ouput?
Asked Answered
H

3

8

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

Hodosh answered 22/2, 2012 at 12:42 Comment(1)
Using KERN_INFO will print to /var/log/messages, maybe KERN_EMERG prints to that file tooOomph
C
8

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");

Chuddar answered 13/4, 2012 at 11:12 Comment(0)
G
3

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.

Geography answered 2/7, 2012 at 6:26 Comment(0)
P
0

You need to modify your syslog to print emergency kernel messages to console (or, specific users or ttys).

There are many syslog daemons, if you don't control the one you use and you're not root - you're out of luck. If you do control the one you use, syslog-ng is pretty good and has examples of how to do this in it's manual.

Principalities answered 22/2, 2012 at 12:47 Comment(1)
Could you please give an example? I find it very hard to understand syslog-ng as non-expert.Hodosh

© 2022 - 2024 — McMap. All rights reserved.