home *** CD-ROM | disk | FTP | other *** search
/ ftp.mayn.de / ftp.mayn.de-pub.zip / ftp.mayn.de-pub / apple / apple_unix / Daemons / INN.loadave.c.-cc < prev    next >
Text File  |  2017-03-06  |  1KB  |  66 lines

  1. /*  $Revision: 1.3 $
  2. **
  3. */
  4. #include "nnrpd.h"
  5. #if    NNRP_LOADLIMIT > 0
  6. #include <nlist.h>
  7. #if 0
  8. STATIC struct nlist NameList[] = {
  9.     { "_avenrun" },
  10. #define    X_AVENRUN    0
  11.     { NULL }
  12. };
  13. #endif
  14. STATIC struct nlist NameList[2];
  15. #define    X_AVENRUN    0
  16.  
  17.  
  18. /*
  19. **  Get the current load average as an integer.
  20. */
  21. int
  22. GetLoadAverage()
  23. {
  24.     int        fd;
  25.     int        oerrno;
  26. #if    defined(FSCALE)
  27.     long    avenrun[3];
  28. #else
  29.     double    avenrun[3];
  30. #endif    /* defined(FSCALE) */
  31.  
  32.     fd = open("/dev/kmem", 0, 0);
  33.     if (fd < 0)
  34.     return -1;
  35.  
  36. strcpy(NameList[0]._n._n_name, "_avenrun");
  37. NameList[0]._n._n_name[0] = NULL;
  38.  
  39. #if    defined(HPUX)
  40.     (void)nlist("/hp-ux", NameList);
  41. #else
  42. #if    defined(SUNOS5)
  43.     (void)nlist("/dev/ksyms", NameList);
  44. #else
  45.     (void)nlist("/vmunix", NameList);
  46. #endif    /* defined(SUNOS5) */
  47. #endif    /* !defined(HPUX) */
  48.     if (NameList[0].n_type == 0
  49.      || lseek(fd, (off_t) NameList[X_AVENRUN].n_value, SEEK_SET) == -1
  50.      || read(fd, (char *)avenrun, sizeof avenrun) != sizeof avenrun) {
  51.     oerrno = errno;
  52.     (void)close(fd);
  53.     errno = oerrno;
  54.     return -1;
  55.     }
  56.  
  57.     (void)close(fd);
  58.  
  59. #if    defined(FSCALE)
  60.     return (int)(avenrun[0] + FSCALE / 2) >> FSHIFT;
  61. #else
  62.     return (int)(avenrun[0] + 0.5);
  63. #endif    /* defined(FSCALE) */
  64. }
  65. #endif    /* NNRP_LOADLIMIT > 0 */
  66.