[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SUMMERY: how to get kernel variables using c



First of all thanks to everyone who answered
this is truely a very good mailing list,
I was ammazed by the number of answers and
the response time that was very fast.

all the answers i got detailed the following system calls/ c functions:
Table - a very usefull system call which can get real time details on the
system
getsysinfo, sysconf, sysinfo - get fixed variables on the system

detailed information on this functions can found in man "function"

here is a sample program that Paul A Sand sent me:

#include <sys/table.h>
#include <stdio.h>
#include <time.h>

main()
{
    struct tbl_sysinfo stab;
    struct tbl_loadavg ltab;

    table(TBL_SYSINFO, 0, &stab, 1, sizeof(struct tbl_sysinfo));
    printf("System was booted at %ld\n", stab.si_boottime);
    printf("System up %0.2f days\n", 
	(time(NULL) - stab.si_boottime)/86400.0);

    table(TBL_LOADAVG, 0, &ltab, 1, sizeof(struct tbl_loadavg));
    if (ltab.tl_lscale == 0) {
	printf("Load averages: %0.2f, %0.2f, %0.2f\n",
	    ltab.tl_avenrun.d[0], 
	    ltab.tl_avenrun.d[1], 
	    ltab.tl_avenrun.d[2]);
    }
    else {
	printf("Load averages: %0.2f, %0.2f, %0.2f\n",
	    ((double) ltab.tl_avenrun.l[0])/ltab.tl_lscale, 
	    ((double) ltab.tl_avenrun.l[1])/ltab.tl_lscale, 
	    ((double) ltab.tl_avenrun.l[2])/ltab.tl_lscale);
    }
	
}