On Jul 28, 2005, at 6:34 AM, Mekhala Patil wrote:
I want to print current date and time in a kernel module. I have also tried to use gettimeofday() by including sys/time.h But still it says undeclared.
You don't really want to do this; you just think you do. 8)
1) do we have direct functions that we could use in kernel?
No.
2) Can get time from epoch using gettimeofday? So, how do I convert it to the current date and time string. Is there something similar to userspace ctime in kernel?
No.
The kernel has no notion of the "time of day"; it is purely a userland conceit. It's quite possible, common and correct for different parts of the system to have different ideas about the current time of day. The kernel only knows about absolute time.
If you use any of the standard kernel logging facilities, your messages will be timestamped automatically by the logging system. Provided you only care about a human-readable representation of "now", there's no need to do anything at all with the time in your kernel code - just call IOLog, logprintf(), etc.
If you need some way of printing "then" as well as "now", you will need a userland component as Drew points out.
= Mike