home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / Editors / mjovesrc.zoo / loadavg.c < prev    next >
C/C++ Source or Header  |  1992-04-04  |  2KB  |  98 lines

  1. /***************************************************************************
  2.  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  3.  * is provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is    *
  5.  * included in all the files.                                              *
  6.  ***************************************************************************/
  7.  
  8. #include "jove.h"
  9.  
  10. #ifdef    LOAD_AV
  11. # if    defined(BSD4_2) && !defined(BSD2_10)
  12. #   if    defined(PURDUE_EE) && (defined(vax) || defined(gould))
  13.  
  14. void
  15. closekmem()
  16. {
  17. }
  18.  
  19. int
  20. get_la()
  21. {
  22.     return loadav(0);
  23. }
  24.  
  25. #   else    /* !(defined(PURDUE_EE) && (defined(vax) || defined(gould))) */
  26.  
  27. #ifdef    sun
  28. #   include <sys/param.h>
  29. #endif
  30. #include <nlist.h>
  31.  
  32. /*
  33.  * struct nlist has different sizes on various machines.  So we
  34.  * deliberately initialize only the first element.
  35.  */
  36. static struct    nlist nl[] = {
  37.     { "_avenrun" },
  38. #define    X_AVENRUN    0
  39.     { "" },
  40. };
  41.  
  42. static int    kmem = 0;
  43.  
  44. void
  45. closekmem()
  46. {
  47.     if (kmem > 0)
  48.         close(kmem);
  49. }
  50.  
  51. int
  52. get_la()
  53. {
  54. #ifdef    sun
  55.     long    avenrun[3];
  56. #else
  57.     double    avenrun[3];
  58. #endif
  59.     extern long    lseek proto((int, long, int));
  60.  
  61.     if (kmem == -1) {
  62.         return 400;    /* So shell commands will say "Chugging" */
  63.     } else if (kmem == 0) {
  64.         if ((kmem = open("/dev/kmem", 0)) == -1) {
  65.             f_mess("Can't open kmem for load average.");
  66.             return 400;
  67.         }
  68.         nlist("/vmunix", nl);
  69.     }
  70.     lseek(kmem, (long) nl[X_AVENRUN].n_value, 0);
  71.     read(kmem, (UnivPtr) avenrun, sizeof(avenrun));
  72. #ifdef    sun
  73.     return (int) (avenrun[0] * 100L / FSCALE);
  74. #else
  75.     return (int) (avenrun[0] * 100. + .5);
  76. #endif
  77. }
  78.  
  79. #    endif  /* !(defined(PURDUE_EE) && (defined(vax) || defined(gould))) */
  80. #  else    /* !(defined(BSD4_2) && !defined(BSD2_10)) */
  81.  
  82. void
  83. closekmem()
  84. {
  85. }
  86.  
  87. int
  88. get_la()
  89. {
  90.     short    avg[3];
  91.  
  92.     gldav(avg);
  93.     return (int) (avg[0]*100L / 256);
  94. }
  95.  
  96. #  endif    /* !(defined(BSD4_2) && !defined(BSD2_10)) */
  97. #endif    /* LOAD_AV */
  98.