diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-26 18:23:13 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-26 18:23:13 +0000 |
commit | 512499c8cab30684785c6b116abbb7c868ac5be9 (patch) | |
tree | 85b99d5221125f9ab56c80440f85241964b16290 | |
parent | ec9781d5e4ff39a174c7f34c7cc5d02b94612e04 (diff) | |
download | busybox-w32-512499c8cab30684785c6b116abbb7c868ac5be9.tar.gz busybox-w32-512499c8cab30684785c6b116abbb7c868ac5be9.tar.bz2 busybox-w32-512499c8cab30684785c6b116abbb7c868ac5be9.zip |
ps: fix RSS parsing (rss field in /proc/PID/stat is in pages, not bytes)
-rw-r--r-- | include/libbb.h | 6 | ||||
-rw-r--r-- | libbb/procps.c | 19 |
2 files changed, 18 insertions, 7 deletions
diff --git a/include/libbb.h b/include/libbb.h index e514fe2f2..89a1695fa 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -881,12 +881,12 @@ enum { COMM_LEN = TASK_COMM_LEN }; | |||
881 | enum { COMM_LEN = 16 }; | 881 | enum { COMM_LEN = 16 }; |
882 | #endif | 882 | #endif |
883 | #endif | 883 | #endif |
884 | typedef struct { | 884 | typedef struct procps_status_t { |
885 | DIR *dir; | 885 | DIR *dir; |
886 | uint8_t shift_pages_to_bytes; | ||
887 | uint8_t shift_pages_to_kb; | ||
886 | /* Fields are set to 0/NULL if failed to determine (or not requested) */ | 888 | /* Fields are set to 0/NULL if failed to determine (or not requested) */ |
887 | /*char *cmd;*/ | ||
888 | char *argv0; | 889 | char *argv0; |
889 | /*char *exe;*/ | ||
890 | USE_SELINUX(char *context;) | 890 | USE_SELINUX(char *context;) |
891 | /* Everything below must contain no ptrs to malloc'ed data: | 891 | /* Everything below must contain no ptrs to malloc'ed data: |
892 | * it is memset(0) for each process in procps_scan() */ | 892 | * it is memset(0) for each process in procps_scan() */ |
diff --git a/libbb/procps.c b/libbb/procps.c index aa207af6f..8d3aea332 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -95,8 +95,15 @@ static int read_to_buf(const char *filename, void *buf) | |||
95 | 95 | ||
96 | procps_status_t *alloc_procps_scan(int flags) | 96 | procps_status_t *alloc_procps_scan(int flags) |
97 | { | 97 | { |
98 | unsigned n = getpagesize(); | ||
98 | procps_status_t* sp = xzalloc(sizeof(procps_status_t)); | 99 | procps_status_t* sp = xzalloc(sizeof(procps_status_t)); |
99 | sp->dir = xopendir("/proc"); | 100 | sp->dir = xopendir("/proc"); |
101 | while (1) { | ||
102 | n >>= 1; | ||
103 | if (!n) break; | ||
104 | sp->shift_pages_to_bytes++; | ||
105 | } | ||
106 | sp->shift_pages_to_kb = sp->shift_pages_to_bytes - 10; | ||
100 | return sp; | 107 | return sp; |
101 | } | 108 | } |
102 | 109 | ||
@@ -229,8 +236,10 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags) | |||
229 | &rss); | 236 | &rss); |
230 | if (n != 10) | 237 | if (n != 10) |
231 | break; | 238 | break; |
232 | sp->vsz = vsz >> 10; /* vsize is in bytes and we want kb */ | 239 | /* vsz is in bytes and we want kb */ |
233 | sp->rss = rss >> 10; | 240 | sp->vsz = vsz >> 10; |
241 | /* vsz is in bytes but rss is in *PAGES*! Can you believe that? */ | ||
242 | sp->rss = rss << sp->shift_pages_to_kb; | ||
234 | sp->tty_major = (tty >> 8) & 0xfff; | 243 | sp->tty_major = (tty >> 8) & 0xfff; |
235 | sp->tty_minor = (tty & 0xff) | ((tty >> 12) & 0xfff00); | 244 | sp->tty_minor = (tty & 0xff) | ((tty >> 12) & 0xfff00); |
236 | #else | 245 | #else |
@@ -250,8 +259,10 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags) | |||
250 | cp = skip_fields(cp, 3); /* cutime, cstime, priority */ | 259 | cp = skip_fields(cp, 3); /* cutime, cstime, priority */ |
251 | tasknice = fast_strtoul_10(&cp); | 260 | tasknice = fast_strtoul_10(&cp); |
252 | cp = skip_fields(cp, 3); /* timeout, it_real_value, start_time */ | 261 | cp = skip_fields(cp, 3); /* timeout, it_real_value, start_time */ |
253 | sp->vsz = fast_strtoul_10(&cp) >> 10; /* vsize is in bytes and we want kb */ | 262 | /* vsz is in bytes and we want kb */ |
254 | sp->rss = fast_strtoul_10(&cp) >> 10; | 263 | sp->vsz = fast_strtoul_10(&cp) >> 10; |
264 | /* vsz is in bytes but rss is in *PAGES*! Can you believe that? */ | ||
265 | sp->rss = fast_strtoul_10(&cp) << sp->shift_pages_to_kb; | ||
255 | #endif | 266 | #endif |
256 | 267 | ||
257 | if (sp->vsz == 0 && sp->state[0] != 'Z') | 268 | if (sp->vsz == 0 && sp->state[0] != 'Z') |