How do I read the load average values from /dev/kmem?
Orachat Choedamphai
orachat at seashell.seas.ucla.edu
Fri Mar 23 11:37:27 AEST 1990
Hello,
I'm trying to get the value of the variable "avenrun" from /dev/kmem. The
following is a program that I used. Could someone please tell me what I did
wrong or maybe someone could send me a C program that will do this job?
I would appreciate any help or suggestion. Thank you in advance.
_Orachat
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/file.h>
#include <a.out.h>
#define UNIX "/unix"
int kmemf; /* descriptor of /dev/kmem */
struct nlist nl[2];
extern int errno;
main ()
{
float avenrun[3];
(void) strcpy (nl[0].n_name, "avenrun");
(void) strcpy (nl[1].n_name, "0");
nlist(UNIX, nl);
if (nl[0].n_value == 0) {
fprintf (stderr, "/vmunix: No namelist\n");
exit(1);
}
printf ("address = %d\n", nl[0].n_value);
if ((kmemf = open("/dev/kmem", O_RDONLY)) < 0) {
perror ("/dev/kmem");
exit (1);
}
if (lseek (kmemf, (off_t)nl[0].n_value, 0) < 0)
printf ("lseek failed\n");;
(void) read (kmemf, (char *)avenrun, sizeof(avenrun));
printf ("load = %e,%e,%e\n", avenrun[0], avenrun[1], avenrun[2]);
}
More information about the Comp.unix.aux
mailing list