32 |
|
#include <stdio.h> |
33 |
|
#include <string.h> |
34 |
|
#endif |
35 |
– |
#ifdef ALLBSD |
35 |
|
#ifdef FREEBSD |
36 |
|
#include <sys/types.h> |
37 |
|
#include <sys/sysctl.h> |
39 |
– |
#else |
40 |
– |
#include <sys/param.h> |
41 |
– |
#include <sys/sysctl.h> |
42 |
– |
#endif |
38 |
|
#include <unistd.h> |
39 |
|
#endif |
40 |
|
|
53 |
|
char *line_ptr; |
54 |
|
FILE *f; |
55 |
|
#endif |
61 |
– |
#ifdef ALLBSD |
62 |
– |
int mib[2]; |
56 |
|
#ifdef FREEBSD |
57 |
+ |
int mib[2]; |
58 |
+ |
u_long physmem; |
59 |
+ |
size_t size; |
60 |
|
u_int free_count; |
61 |
|
u_int cache_count; |
62 |
|
u_int inactive_count; |
65 |
|
#ifdef NETBSD |
66 |
|
struct uvmexp *uvm; |
67 |
|
#endif |
72 |
– |
u_long physmem; |
73 |
– |
size_t size; |
74 |
– |
#endif |
68 |
|
|
69 |
|
#ifdef SOLARIS |
70 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
121 |
|
|
122 |
|
#endif |
123 |
|
|
124 |
< |
#ifdef ALLBSD |
124 |
> |
#ifdef FREEBSD |
125 |
|
/* Returns bytes */ |
126 |
|
mib[0] = CTL_HW; |
127 |
|
mib[1] = HW_PHYSMEM; |
132 |
|
mem_stat.total = physmem; |
133 |
|
|
134 |
|
/*returns pages*/ |
142 |
– |
#ifdef FREEBSD |
135 |
|
size = sizeof free_count; |
136 |
|
if (sysctlbyname("vm.stats.vm.v_free_count", &free_count, &size, NULL, 0) < 0){ |
137 |
|
return NULL; |
163 |
|
mem_stat.free=(free_count*pagesize)+(inactive_count*pagesize); |
164 |
|
mem_stat.used=physmem-mem_stat.free; |
165 |
|
#endif |
166 |
+ |
|
167 |
|
#ifdef NETBSD |
175 |
– |
/* FIXME This is not consistent with the FreeBSD logic above. */ |
168 |
|
if ((uvm = get_uvmexp()) == NULL) { |
169 |
|
return NULL; |
170 |
|
} |
171 |
+ |
mem_stat.total = uvm->pagesize * uvm->npages; |
172 |
|
mem_stat.cache = uvm->pagesize * (uvm->filepages + uvm->execpages); |
173 |
< |
mem_stat.free = uvm->pagesize * uvm->free; |
174 |
< |
mem_stat.used = uvm->pagesize * (uvm->npages - uvm->free); |
173 |
> |
mem_stat.free = uvm->pagesize * (uvm->free + uvm->inactive); |
174 |
> |
mem_stat.used = mem_stat.total - mem_stat.free; |
175 |
|
#endif |
183 |
– |
#endif |
176 |
|
|
177 |
|
return &mem_stat; |
186 |
– |
|
178 |
|
} |