home *** CD-ROM | disk | FTP | other *** search
- /* ugetloads(ls)
- * fload ld[3];
- *
- * Puts the 1, 5, and 15 minute load averages in the float
- * array passed to it. This program calls upon uptime(1)
- * which could have different ways of printing ie. with bsd4.2
- * " 9:34pm up 11 hrs, 3 users, load average: 0.25, 0.22, 0.24 "
- * notice the commas -- ^ --- ^.
- * while bsd4.1 does not print commas. The BSD41 define will
- * take care of this if that is your system, it defaults to
- * the 4.2 version.
- */
-
- #include <stdio.h>
-
- FILE *popen();
-
- ugetloads(ld)
- float ld[3];
- {
- FILE *stream;
-
- if((stream = popen("/usr/ucb/uptime","r")) == NULL)
- return(-1);
-
- #ifdef BSD41
- fscanf(stream,"%*[^l] load average: %f %f %f", &ld[0],&ld[1],&ld[2]);
- #else
- fscanf(stream,"%*[^l] load average: %f, %f, %f", &ld[0],&ld[1],&ld[2]);
- #endif BSD41
- pclose(stream);
- return(NULL);
- }
-
-