home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume23 / sps2 / part03 / percentmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-08  |  1.1 KB  |  46 lines

  1. # ifndef lint
  2. static char SccsId[] =  "@(#)percentmem.c    1.1\t10/1/88" ;
  3. # endif
  4.  
  5. # include       "sps.h"
  6. # ifndef SUNOS40
  7. # include       <h/text.h>
  8. # endif
  9. # ifdef BSD42
  10. # include    <machine/pte.h>
  11. # else
  12. # include       <h/pte.h>
  13. # include       <h/vmparam.h>
  14. # endif
  15. # include       <h/vmmac.h>
  16.  
  17. /* PERCENTMEM - Returns the percentage of real memory used by this process */
  18. double  percentmem ( p )
  19.  
  20. register struct process         *p ;
  21.  
  22. {
  23. # ifndef SUNOS40
  24.     register struct text    *tp ;
  25. # endif
  26.     int                     szptudot ;
  27.     double                  fracmem ;
  28.     extern struct info      Info ;
  29.  
  30. # ifdef SUNOS40
  31.     if ( !(p->pr_p.p_flag & SLOAD) )
  32.         return ( 0.0 ) ;
  33.     szptudot = UPAGES ;
  34.     fracmem = ( (double)p->pr_p.p_rssize + szptudot ) ;
  35. # else
  36.     tp = p->pr_p.p_textp ;
  37.     if ( !(p->pr_p.p_flag & SLOAD) || !tp )
  38.         return ( 0.0 ) ;
  39.     szptudot = UPAGES + clrnd( ctopt( p->pr_p.p_dsize + p->pr_p.p_ssize ) );
  40.     fracmem = ( (double)p->pr_p.p_rssize + szptudot ) / CLSIZE ;
  41.     if ( tp->x_ccount )
  42.         fracmem += ((double)tp->x_rssize)/CLSIZE/tp->x_ccount ;
  43. # endif
  44.     return ( 100.0 * fracmem / (double)Info.i_ecmx ) ;
  45. }
  46.