1: /*(@(#)getloadave.c 1.2 /ra/csr/presotto/hacks/src/worm/sccs/s.getloadave.c)*/
2: #include <sys/types.h>
3: #include <nlist.h>
4: #include <sys/stat.h>
5:
6: #define MAXRETRIES 20
7:
8: struct nlist nl[] = {
9: #define NL_AVENRUN 0
10: { "_avenrun" },
11: 0
12: };
13: int kmemf = -1; /* fd for kmem */
14: time_t vmunixdate = 0; /* update time for vmunix */
15:
16: initnlist ()
17: {
18: int i;
19: struct nlist *nlp;
20: struct stat sbuf;
21:
22: i = stat ("/vmunix", &sbuf);
23: if (i == -1) {
24: error ("can't read /vmunix");
25: }
26: if (vmunixdate != sbuf.st_mtime) {
27: for (i = 0; i < MAXRETRIES; sleep (5), i++) {
28: for (nlp = &nl[sizeof (nl) / sizeof (nl[0])]; --nlp >= nl; ) {
29: nlp->n_value = 0;
30: nlp->n_type = 0;
31: }
32: nlist("/vmunix", nl);
33: if (nl[0].n_value == 0) {
34: warn ("/vmunix namelist botch");
35: continue;
36: }
37: break;
38: }
39: if (i >= MAXRETRIES)
40: exit (-1);
41: vmunixdate = sbuf.st_mtime;
42: }
43:
44: if (kmemf == -1) {
45: kmemf = open("/dev/kmem", 0);
46: if (kmemf < 0) {
47: error ("opening /dev/kmem");
48: }
49: }
50: }
51:
52:
53: /*
54: * Get the current load average
55: */
56: getloadave (avenrun)
57: double *avenrun;
58: {
59: double template[3];
60:
61: initnlist ();
62: (void) lseek(kmemf, (long)nl[NL_AVENRUN].n_value, 0);
63: (void) read(kmemf, (char *)avenrun, sizeof (template));
64: }
Defined functions
Defined variables
kmemf
defined in line
13; used 5 times
nl
defined in line
8; used 7 times
Defined macros