The linux kernel provides a number of interfaces to manage time. getnstimeofday is one of them, which gives the time in seconds and nanoseconds . The function is implemented in "timekeeping32.h" and returns a structure of the type timespec which has two members.
To print the time, we only need to print the values of tv_sec and tv_nsec which gets filled by the call to the function getnstimeofday.
In the following example code, we have created a proc entry called gettime, which prints out the values of seconds and nanoseconds when read.
Save the above code as proc_read_gettimeofday.c and compile the code using the following makefile.
Compile and insert the module using
To see the output, just read the proc entry gettime, using the cat command.
To print the time, we only need to print the values of tv_sec and tv_nsec which gets filled by the call to the function getnstimeofday.
In the following example code, we have created a proc entry called gettime, which prints out the values of seconds and nanoseconds when read.
Save the above code as proc_read_gettimeofday.c and compile the code using the following makefile.
Compile and insert the module using
To see the output, just read the proc entry gettime, using the cat command.
No comments:
Post a Comment