I'm writing a Linux character driver which can print system logs in user space. Just as the command 'dmesg' does. I've learned that all the log that we print with 'printk' will be sent to a space named ring buffer. So I have the questions:
What you are looking for is /proc/kmsg
. This is the kernel ring buffer!
Yes, this is inside kernel space. Any process trying to read it should have super user privileges to read it!
How to read it the ring buffer? Here is a beautiful illustration from IBM Developerworks
dmesg
would be your first resort! How does dmesg accomplish its task? By a call to syslog()
! How does syslog do its job? Through the system call interface which in turn call do_syslog()
. do_syslog()
does the finishing act like this.
Here are a few more resources to get you more info about /proc/kmsg
and kernel logging in general-