0

I am on a shared host and I am only allowed to use so much RAM. How can I find out how much I am currently using ? I know top and free and ps and some other tools, but they usually only display memory for the entire system, not user-specific. There is also this SF post which gives me the impression measuring memory usage is not a s trivial as it seems.

Maybe some esoteric ps switch plus some shell scripting ? I am reasonably sure I am not the first one with that issue, so there is probably a straight-forward solution, just can't seem to find it...

ssc
  • 1,159
  • 3
  • 17
  • 30
  • Which form of VPS are you using, VM based, like vmware or xen ? or container based like Virtuozzo, OpenVZ or Linux V Servers ? – Dave Cheney Feb 25 '10 at 06:19

1 Answers1

1

The following should show the total resident set size (non-swapped physical memory) in KB.

ps uU username | awk '/^username/ { total += $6 } END { print total }'

If you need the virtual memory size, try:

ps uU username | awk '/^username/ { total += $5 } END { print total }'
fission
  • 3,601
  • 2
  • 21
  • 31
  • I'd combine the two.... ps uU username| awk '/^username/ { vtotal += $5 } { rtotal += $6} END { print "R " rtotal " V " vtotal }' This is for a linux machine, ps flags and awk anchors will vary with different versions of ps – quadruplebucky Feb 26 '10 at 17:04
  • The OP mentioned free(1), which afaik is a Linux-ism. And the 'u' option without hyphen puts ps into BSD-style output mode, which is fairly consistent across platforms. (I tested on Linux, OS X, and FreeBSD.) But I do like the idea of producing combined output! – fission Feb 26 '10 at 17:30