-
Notifications
You must be signed in to change notification settings - Fork 1
/
lav.c
56 lines (46 loc) · 947 Bytes
/
lav.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* $Log: lav.c,v $
* Revision 1.1 84/11/10 14:45:41 mikec
* Initial revision
*
*
*/
/*
*
* lav.c -- Print the load average.
* lav must be setuid root (or appropriote uid) that can read
* /dev/kmem. On some systems, such as ours, permissions to
* kmem are turned off for security reasons.
*
*/
#include <nlist.h>
#include <stdio.h>
struct nlist nl[] = {
{ "_avenrun" },
{ "" },
};
int kmem;
double avenrun[3];
main()
{
register int i;
if ((kmem = open("/dev/kmem", 0)) < 0) {
fprintf(stderr, "No kmem\n");
exit(1);
}
nlist("/vmunix", nl);
if (nl[0].n_type==0) {
fprintf(stderr, "No namelist\n");
exit(1);
}
/*
* Print 1, 5, and 15 minute load averages.
* (Found by looking in kernel for avenrun).
*/
lseek(kmem, (long)nl[0].n_value, 0);
read(kmem, avenrun, sizeof(avenrun));
for (i = 0; i < (sizeof(avenrun)/sizeof(avenrun[0])); i++) {
printf("%.2f ", avenrun[i]);
}
printf("\n");
}