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 |
* |
* |
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 |
} |
} |
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 |