![]() |
|
|
| Subject:
Linux kernel code to write to a file
Category: Computers > Programming Asked by: ga1000-ga List Price: $10.00 |
Posted:
10 Feb 2003 15:43 PST
Expires: 12 Mar 2003 15:43 PST Question ID: 159694 |
Would like to know a short program of Linux kernel code (not user space) to show me how to write a character or string output to a disk file. I currently use printk for debug purpose and have to look at the output at the message file, which is a very tedious process. | |
| |
|
|
| Subject:
Re: Linux kernel code to write to a file
Answered By: maniac-ga on 10 Feb 2003 17:31 PST |
Hello Ga1000,
You are asking for a way to gather debugging messages from the "latest
run".
Using the existing syslog facility, add
kern.debug /var/log/kern.debug
to capture the debugging messages to the file /var/log/kern.debug.
Restart the syslogd server to make the changes take effect
killall -HUP syslogd
(or similar method)
In your driver use
printk ( KERN_DEBUG "-- your message here--" );
to generate the debug messages. Run your test, review the output in
/var/log/kern.debug. Before starting the next run, you can "rotate"
the log file so you can check the progress of separate runs.
To "rotate" the log file, a command such as logrotate can be used
logrotate -f -s /var/lib/logrotate.kd.status /etc/logrotate.kd
where /etc/logrotate.kd has contents
/var/log/kern.debug {
rotate 10
daily
postrotate
/sbin/killall -HUP syslogd
endscript
}
which will keep logfiles for the last 10 tests in separate files named
/var/log/kern.debug.1, .2, etc.
If you need to separate data more finely, unique strings would still
work - use grep on the log file to pull out those specific items.
References:
Syslog.conf man page for Linux:
http://www.die.net/doc/linux/man/man5/syslog.conf.5.html
Example code using printk ( KERN_DEBUG ...)
http://www.linuxdevices.com/eljonline/misc/6226l1.html
Man page for logrotate
http://nodevice.com/sections/ManIndex/man0735.html
--Maniac |
|
| There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |