kernel function to print uptime in seconds?
Hi there,
I'm trying to compile a kernel module which will print the uptime since booting in seconds. This is what I have so far: Code:
#include <linux/module.h> /* Needed by all modules */ make[1]: Map '/usr/src/kernels/4.0.6-300.fc22.x86_64' wordt binnengegaan CC [M] /home/mastag/time.o /home/mastag/time.c: In functie ‘init_module’: /home/mastag/time.c:14:23: fout: ‘sysinfo’ undeclared (first use in this function) printk("Uptime: ", sysinfo.uptime, "\n"); ^ /home/mastag/time.c:14:23: note: each undeclared identifier is reported only once for each function it appears in scripts/Makefile.build:264: recept voor doel '/home/mastag/time.o' is mislukt make[2]: *** [/home/mastag/time.o] Fout 1 Why is it undeclared? I've included sysinfo.h which has the sysinfo struct right? linux/sysinfo.h contains: Code:
struct sysinfo { |
Is this just for exercise? Normally you can get the uptime in seconds with cat /proc/uptime
|
No exercise just trying to make some sample kernel modules.
I can get the uptime easily from userspace using a shell script, and I believe the struct in the linux/sysinfo.h kernel header is for using it with glibc. I think the kernel itself doesn't have a function for calculating it in seconds. I guess I have to calculate it myself using the jiffies or something.. |
In your code so far, you refer to the sysinfo structure as though it were a variable. Hence the compile-time error. Simply surf the kernel source-code for correct examples of how to find the location of this structure and how to use its contents.
|
All times are GMT -5. The time now is 03:27 PM. |