25

I run top on busybox and it shows all processes and their virtual memory size.

How do I determine how much RAM is being used by each process?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Collin Anderson
  • 1,831
  • 2
  • 12
  • 8

3 Answers3

25

On busybox, "ps" doesn't have a "-o" option, but "ps l" includes the RSS column.

If the underlying O/S is Linux, you can also get more specific details for a given process from:

cat /proc/PID/status

The output looks like this:

Name:   ash
State:  S (sleeping)
Tgid:   1990
Pid:    1990
PPid:   1
TracerPid:  0
Uid:    0   0   0   0
Gid:    0   0   0   0
FDSize: 32
Groups: 0 
VmPeak:     1592 kB
VmSize:     1592 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:       552 kB
VmRSS:       552 kB
VmData:      268 kB
VmStk:       136 kB
VmExe:       688 kB
VmLib:       472 kB
VmPTE:        16 kB
VmSwap:        0 kB
Threads:    1
SigQ:   14/340
SigPnd: 00000000000000000000000000000000
ShdPnd: 00000000000000000000000000000000
SigBlk: 00000000000000000000000000000000
SigIgn: 00000000000000000000000004804004
SigCgt: 00000000000000000000000000080002
CapInh: 0000000000000000
CapPrm: ffffffffffffffff
CapEff: ffffffffffffffff
CapBnd: ffffffffffffffff
Cpus_allowed:   1
Cpus_allowed_list:  0
voluntary_ctxt_switches:    49
nonvoluntary_ctxt_switches: 15

In this list, VmRSS is the current resident set, and VmHWM is the resident set high-water-mark.

Andrew Fullford
  • 351
  • 3
  • 4
  • [BusyBox `ps` has supported `-o` since 2006](https://github.com/brgl/busybox/commit/9494919ea5116075e16daac1355265b023419cdc), but needs to be built with the "DESKTOP" build option. – JdeBP Jan 29 '20 at 10:43
23
ps -o pid,user,vsz,rss,comm,args

The 4th column (rss) is the resident set size, the non-swapped physical memory used by a task, in kiloBytes.

nemoinis
  • 239
  • 1
  • 3
0
 ps -q pid -o rss= 

this should work

abhiraj
  • 19
  • 2
    Please add what platform you are running under. My `ps` has no `-q` option and I'm running suse linux. – JamesL Jan 28 '20 at 17:57
  • 1
    It appears that the [busybox version](https://github.com/brgl/busybox/blob/master/procps/ps.c) of `ps` (latest commit 4e08a12 of Jan. 2017) doesn't have that option either. – AdminBee Jan 29 '20 at 08:03
  • **`-q` pidlist** Select by PID (quick mode). This selects the processes whose process ID numbers appear in pidlist. With this option ps reads the necessary info only for the pids listed in the pidlist and doesn't apply additional filtering rules. The order of pids is unsorted and preserved. No additional selection options, sorting and forest type listings are allowed in this mode. Identical to q and --quick-pid. – Kevdog777 Jan 29 '20 at 08:55
  • @Kevdog777 could you specify on which platforms this is implemented? It does not seem to be a [POSIX requirement](https://pubs.opengroup.org/onlinepubs/009695399/utilities/ps.html). Besides, the OP explicitly asked about the busybox environment ... – AdminBee Jan 29 '20 at 12:44
  • 1
    Sorry @AdminBee, I found that here: http://man7.org/linux/man-pages/man1/ps.1.html as people didn't know what the `-q` meant. So it just says `Linux`. – Kevdog777 Jan 29 '20 at 14:21
  • Actually, it says procps-ng, and no-one asked what the `-q` meant. That is the wrong manual for a different program. The BusyBox manual is of course [`man busybox`](https://busybox.net/downloads/BusyBox.html#ps). And what people asked was what platform and what `ps` command that was. Because it isn't the one in the question. – JdeBP Jan 29 '20 at 18:46