I.T. Security and Linux Administration

Apr 24 2013   1:54PM GMT

Quick Shell Trick – Find Memory Usage

Eric Hansen Eric Hansen Profile: Eric Hansen

Unlike Windows (hear me out), its not as easy to find out how much memory a process is using.  Tools like ps report the RSS (resident set size), which “significantly overestimate memory usage” while PSS (proportional set size) measures “each application’s ‘fair share’ of each shared area to give a realistic measure.” (source: http://www.selenic.com/smem/).

When you’re trying to find bottlenecks (and don’t want to use tools like Valgrind), or get an actual representation of how much memory a process is using, this means that ps is more or less out of the question.  There’s always “top”, but personally I’m not sure what type of memory usage it reports and I’m too lazy to research that.

After doing some digging around, I discovered smem (linked above as source).  Its a Python script that reports different types of memory (including PSS).  Installing it is easy (it should be in your package manager), and using it is even easier.

I’d like to start off by saying that I’m fairly certain there’s an easier way of doing this than how I’m going to show, but I haven’t really felt like going through the arguments.

To get the PSS of a process, just run this command:

smem | grep <name> | grep -v “grep” | awk ‘{print $6}’

Replacing “<name>” with either the program or the PID.  Just like ps, this will generate a listing for the grep command, so we exclude all grep commands from the list, and then print the 6th column (PSS).

The output by default is in bytes, but if you want it more human-readable, just pass “-k” to the arguments of smem.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: