This source file includes following definitions.
- check_avg
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <stdlib.h>
20
21 #include "signature.h"
22 SIGNATURE_CHECK (getloadavg, int, (double [], int));
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <unistd.h>
27
28 static void
29 check_avg (int minutes, double avg, int printit)
30 {
31 if (printit)
32 printf ("%d-minute: %f ", minutes, avg);
33 else
34 {
35
36 if (avg < 0.01)
37 printf ("suspiciously low %d-minute average: %f\n", minutes, avg);
38 if (avg > 1000000)
39 printf ("suspiciously high %d-minute average: %f\n", minutes, avg);
40 }
41 if (avg < 0 || avg != avg)
42 exit (minutes);
43 }
44
45
46
47
48
49 int
50 main (int argc, char **argv)
51 {
52 int naptime = 0;
53
54 if (argc > 1)
55 naptime = atoi (argv[1]);
56
57 while (1)
58 {
59 double avg[3];
60 int loads = getloadavg (avg, 3);
61 if (loads == -1)
62 {
63 if (! (errno == ENOSYS || errno == ENOTSUP || errno == ENOENT))
64 return 1;
65 perror ("Skipping test; load average not supported");
66 return 77;
67 }
68 if (loads > 0)
69 check_avg (1, avg[0], argc > 1);
70 if (loads > 1)
71 check_avg (5, avg[1], argc > 1);
72 if (loads > 2)
73 check_avg (15, avg[2], argc > 1);
74 if (loads > 0 && argc > 1)
75 putchar ('\n');
76
77 if (naptime == 0)
78 break;
79 sleep (naptime);
80 }
81
82 return 0;
83 }