libbb/procps.c question

Robin Getz rgetz at blackfin.uclinux.org
Sat Oct 15 18:56:15 UTC 2005


Hi.

I am trying to fix an issue in our system (uClinux-2.6.12/nommu/uclibc) 
where busybox top and ps do not print out the proper memory size.

Both top and ps (from busybox) use the /proc/PID/stat file to grab the 
memory for the application with to 
/user/busybox/libbb/procps.c:procps_scan(). If I look at this file by hand, 
I see:

root:~> cat /proc/21/stat
21 (inetd) S 1 0 0 0 -1 256 0 0 0 0 0 0 0 0 16 0 1 0 144 74112 0 4294967295 
130416708 130438628 130482064 130481600 0 0 0 4102 720897 0 0 0 17 0 0 0

This is put out from linux-2.6.x/fs/proc/array.c:do_task_stat() (which is 
code I don't touch/control).

In order to make things work I needed to:
-------------------------------------------------------
diff -u -r1.1 -r1.2
--- procps.c    25 Jul 2005 01:46:01 -0000      1.1
+++ procps.c    15 Oct 2005 12:08:24 -0000      1.2
@@ -13,6 +13,7 @@

#include <stdlib.h>
#include <unistd.h>
#include <asm/page.h>

+#include <linux/version.h>

#include "libbb.h"

@@ -91,7 +92,9 @@
                 "%*s %*s %*s "         /* cutime, cstime, priority */
                 "%ld "
                 "%*s %*s %*s "         /* timeout, it_real_value, 
start_time */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
                 "%*s "                 /* vsize */
+#endif
                 "%ld",
                 curstatus.state, &curstatus.ppid,
#ifdef CONFIG_FEATURE_CPU_USAGE_PERCENTAGE


@@ -117,11 +120,15 @@
                 else
                         curstatus.state[2] = ' ';

+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
#ifdef PAGE_SHIFT
                 curstatus.rss <<= (PAGE_SHIFT - 10);     /* 2**10 = 1kb */
#else
                 curstatus.rss *= (getpagesize() >> 10);     /* 2**10 = 1kb */
#endif
+#else
+               curstatus.rss >>= 10;   /* rss is in bytes, and we need KB */
+#endif

                 if(save_user_arg0) {
                         sprintf(status, "/proc/%d/cmdline", pid);
-----------------------------------

I am not sure if this depends on kernel version, or uClinux/nommu?

Any pointers appreciated.

Thanks
-Robin




More information about the busybox mailing list