Hello all.
I am trying to write a module and there are some questions in my mind.
First I am trying to write running processes to console.However printk() function doesn't display it properly. Using KERN_EMERG flag, it prints out like
Message from syslogd@johndoe-laptop at Fri Jul 18 18:51:08 2008 ...
johndoe-laptop kernel: [ 4603.244000] soffice.bin
Message from syslogd@johndoe-laptop at Fri Jul 18 18:51:08 2008 ...
johndoe-laptop kernel: [ 4603.244000] insmod
Message from syslogd@johndoe-laptop at Fri Jul 18 18:51:08 2008 ...
johndoe-laptop kernel: [ 4603.244000] kstopmachine
Message from syslogd@johndoe-laptop at Fri Jul 18 18:51:08 2008 ...
johndoe-laptop kernel: [ 4603.244000] udevd
it displays Message from syslogd@... on every printk.
World is a bit tough with printk. Is there any way of using standart libraries (at least studio.h) when writing modules?
And another question. I am supposed to refresh the data in a time interval given by the user as a paramaeter. So i must somehow use time.h or equivalent of it. Is there any source of functions we can use when wiriting modules. I dont know any other function except printk yet.
I am a bit newbie to kernel programming. So please help me :)
Blame your distro for
Blame your distro for configuring syslogd in such a stupid way to print every kernel message to a tty. Usually these should only go to a file in /var/log/.
Module programming
Yes it does , actually. It is also stored in /var/log . But I want to print the results to console screen as well.
As for my other questions, is there anyone who can answer ?
1) Is there any possibility to use standard libraries such as stdio.h when writing modules?
2) Is there any kind of library that is equivalent of time.h. I have to refresh the results at a given time rate and I somehow have to manage time in my module.
KERN_EMERG
emergency messages have to go to the console too! in addition to being logged, of course. less important messages only should go to a file.
KERN_EMERG
Emergency messages go to console but in an unwanted way (at least to me). I mentioned about it in my first post. Any way of printing to console as we do using printf ???
no
no. kernel messages and especially KERN_EMERG ones are meant for emergency calls and not for debugging messages. it is important to know the sender of such a message. kernel space is just not like user space. you can certainly reconfigure syslogd, but that will make your job harder if you get messages about dying harddisks or similar.
you should really mark your debug messages as KERN_DEBUG and configure syslogd to put KERN_DEBUG messages of your subsystem where you want them. you can also use debugfs for your purposes. look at /etc/syslog.conf and the associated manual page.
Using time
Ok, lets go back to the other problem. How can I measure time when programming a module. I tried to use linux/time.h functions but it gives a clock number which I didnt quite get how to make use of.
I want to make the program wait for a given time period , let's say 20 seconds , for example.Then I will print a message like 20 seconds passed. Any code or explanation of how this can be done will be greatly appreciated.
Thanks in advance.
no time.h
as you will know kernel space is totally seperate from user space. kernel space is where the system calls are implemented which you can call in user space, as the ones in time.h. there is a function add_timer() in include/linux/timer.h in the linux (kernel) source, there is even a man page.
For a better output
Hi Ho!
You should try KERN_ALERT instead of KERN_EMERG to have nice output on your screen (hopefully).
Best regards,
Eus