/[monit]/monit/process/sysdep_LINUX.c
ViewVC logotype

Diff of /monit/process/sysdep_LINUX.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by chopp, Wed Aug 13 22:18:43 2003 UTC revision 1.5 by martinp, Tue Sep 9 19:36:40 2003 UTC
# Line 78  Line 78 
78   *   *
79   *  @author Jan-Henrik Haukeland, <hauk@tildeslash.com>   *  @author Jan-Henrik Haukeland, <hauk@tildeslash.com>
80   *  @author Christian Hopp <chopp@iei.tu-clausthal.de>   *  @author Christian Hopp <chopp@iei.tu-clausthal.de>
81     *  @author Martin Pala <martin.pala@iol.cz>
82     *  @author Arkadiusz Miskiewicz <arekm@pld-linux.org>
83   *   *
84   *  @version \$Id$   *  @version \$Id$
85   *   *
# Line 85  Line 87 
87   */   */
88    
89  #define PAGE_TO_KBYTE_SHIFT PAGE_SHIFT-10  #define PAGE_TO_KBYTE_SHIFT PAGE_SHIFT-10
90    #define MEMTOTAL            "MemTotal:"
91    
92  int init_process_info_sysdep(void) {  int init_process_info_sysdep(void) {
93    
94    struct stat buf;    int  memfd;
95        char buf[1024], *ptr;
96    
97    /* I hope this is okay hack to get the total memsize. (-: */    if( (memfd = open("/proc/meminfo", O_RDONLY)) == -1 )
98        return FALSE;
99    
100    if ( stat("/proc/kcore", &buf) != 0 ) {    if( read(memfd, buf, sizeof(buf)) < 0 ) {
101        close(memfd);
102        return FALSE;
103      }
104      close(memfd);
105    
106      if(! (ptr= strstr(buf, MEMTOTAL)) )
107      return FALSE;      return FALSE;
108    
109    }    if( sscanf(ptr+strlen(MEMTOTAL), "%ld", &mem_kbyte_max) != 1 )
110        return FALSE;
111    
112    num_cpus= sysconf(_SC_NPROCESSORS_CONF);    num_cpus= sysconf(_SC_NPROCESSORS_CONF);
113    
   mem_kbyte_max = buf.st_size>>10;  
   
114    return TRUE;    return TRUE;
115    
116  }  }
# Line 156  int get_process_info_sysdep(ProcInfo_T p Line 164  int get_process_info_sysdep(ProcInfo_T p
164    
165    }    }
166    
167    p->mem_percent = (int) ((double) p->mem_kbyte * 1000.0 / mem_kbyte_max);    p->mem_percent = (int)( (double)p->mem_kbyte * 1000 / mem_kbyte_max);
168    
169    /* jiffies -> seconds = 1 / HZ    /* jiffies -> seconds = 1 / HZ
170       HZ is defined in "asm/param.h"  and it is usually 1/100s but on       HZ is defined in "asm/param.h"  and it is usually 1/100s but on

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26