How to use klogd properly?

I am new to Linux and I have a hard time making klogd work properly to display debug messages.
I'm writing Linux driver modules using insmod and rmmod. I have kprint output debug messages but I need to figure out how to have klogd display the debug messages.

It looks like klogd was already initialized during the boot up process (I'm using Ubuntu). So when I entered:
$ klogd -c 8
It says klogd is already running. The question is what do I need to do to prevent klogd from being initialized. And if there is any way to reintialize klogd to a higher level (8) so I can see the debug messages.
Who is Participating?
Duncan RoeConnect With a Mentor Software DeveloperCommented:
Your simplest method is to dispense with klogd altogether. In the attached example
- make sure /proc/kmsg exists (it's possible though unlikely that it doesn't)
- find out the pid of klogd
- kill klogd
- make sure it's gone
- cat /proc/kmsg directly in your window of choice - you'll see everything

I plugged in a USB stick to generate some messages. You don't get timestamps like you would with klogd / syslogd but I imagine that doesn't worry you
07:51:03# ls -l /proc/kmsg 
-r--------  1 root root 0 2008-02-04 07:51 /proc/kmsg
07:54:46# ps ax|grep klogd
 2208 ?        Ss     0:00 /usr/sbin/klogd -c 3 -x
 2214 pts/9    S+     0:00 grep klogd
07:55:00# kill 2208
07:55:45# ps ax|grep klogd
 2216 pts/9    S+     0:00 grep klogd
07:59:17# cat /proc/kmsg
<7>hub 1-0:1.0: state 7 ports 4 chg 0000 evt 0004
<7>ehci_hcd 0000:00:05.2: GetStatus port 2 status 001803 POWER sig=j CSC CONNECT
<7>hub 1-0:1.0: port 2, status 0501, change 0001, 480 Mb/s
<7>hub 1-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x501

Open in new window

Duncan RoeSoftware DeveloperCommented:
Do you mean printk?
You can probably just let klogd run - it intercepts kernel messages and sends them to the syslog subsystem. You might want to tune your /etc/syslog.conf to put kernel messages somewhere convenient to you.
VolgaAuthor Commented:

Yes I mean printk. What I actually want to see are the messages displaying interactively. I would prefer to see those debug messages in the same window after I type the command insmod...
I remember I was able to do that when we were developing driver modules for an embedded Linux device. With the embedded device we were able to customize the environment, I wonder how to do that on a desktop.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Duncan RoeSoftware DeveloperCommented:
The -c argument to klogd affects what goes to the *console*. That is not the same as your current X window - if not running X then it is the VC1. X has/had xconsole which seems to have stopped working for me. Perhaps you can tell syslogd to rout kernel messages to somewhere helpful (like one of your xterms - you'd have to reconfigure syslogd after you knew the pty number)
VolgaAuthor Commented:

I think I'm confused again with all these Linux terms. What I really mean is the console, just like a DOS window or DOS box  in the Windows world.
I'm new to Linux, so please can you let me know how do I configure syslogd, where is it located, and how do I find out the pty number of that console (or box, or window, whatever it is called).
All I want to see are debug messages right after I type the command insmod... in the same console box.

VolgaAuthor Commented:
Apparently this works for me. But I just wonder why we couldn't use klogd -c to display those messsages on the same console. Is it what this klogd command supposed to do?
Duncan RoeSoftware DeveloperCommented:
-c is not necessarily the *same* console as you are working on. It sends output to /dev/console whereas *your* console is /dev/tty (and every process's /dev/tty is potentially different). By default this displays on the first DOS-lookalike screen that you get when you boot linux (assuming you don't boot to a GUI login manager with X-windows started). Did you know you probably have 6 of these? The left & right arrow keys move between them when you also hold down the Alt key. Or you can use Ctl-Alt-{F1 - F6} to change between them. But /dev/console messages only appear on the first one.

By the way, if you background the cat command, you can have its output appear on your screen as you do other stuff:

cat /proc/kmsg&
VolgaAuthor Commented:

Thanks for your help. I just got into this Linux world and this world doesn't look so obvious. There are lots of things to know still.
All Courses

From novice to tech pro — start learning today.