home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / sps3 / part01 / percentmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-08  |  1.2 KB  |  50 lines

  1. # ifndef lint
  2. static char SccsId[] =  "@(#)percentmem.c    1.2\t6/26/91" ;
  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. # ifdef ULTRIX40
  38.     if ( !(p->pr_p.p_sched & SLOAD) || !tp )
  39. # else
  40.     if ( !(p->pr_p.p_flag & SLOAD) || !tp )
  41. # endif
  42.         return ( 0.0 ) ;
  43.     szptudot = UPAGES + clrnd( ctopt( p->pr_p.p_dsize + p->pr_p.p_ssize ) );
  44.     fracmem = ( (double)p->pr_p.p_rssize + szptudot ) / CLSIZE ;
  45.     if ( tp->x_ccount )
  46.         fracmem += ((double)tp->x_rssize)/CLSIZE/tp->x_ccount ;
  47. # endif
  48.     return ( 100.0 * fracmem / (double)Info.i_ecmx ) ;
  49. }
  50.