home *** CD-ROM | disk | FTP | other *** search
- /* getload(what)
- * int what;
- *
- * Returns the 1, 5, or 15 minute load average.
- * Call with getload(1), or getload(5), or getload(15).
- * Defaults to getload(1);
- * The program "getld" must be setgid to read /dev/kmem and
- * located where the execl expects it (/usr/local/lib).
- */
- #include <signal.h>
- #include "loadstuff.h"
-
- float getload(whatave)
- int whatave;
- {
- int loadav;
- float load;
- char *charav = "1 ";
- int status, pid, w;
-
- if(whatave == 15)
- charav = "15";
- if (whatave == 5)
- charav = "5";
-
- /* Now run the getld program, using fork/exec. */
- if ((pid = vfork()) == 0) {
- /* This Line should be changed if the program "getld" is not
- * going to be actually called "getld" or wont be in /usr/local/lib
- */
- execl("/usr/local/lib/getld","getld",charav,0);
- _exit(254);
- }
- while ((w = wait(&status)) != pid && w != -1)
- ;
- if (w == -1)
- status = -1;
-
- loadav = (status >> 8); /* Set loadav to system exit */
-
- load = (float)loadav / 10; /* Get the correct floating point value */
- /* that corresponds to the integer */
- /* exit value we received from getld */
-
- if(loadav == 254) load = NOKMEM;
- if(loadav == 255) load = NONAMELST;
- if(loadav == 250) load = OVERFLOW;
-
- return(load);
- }
-