2

I can see swap's total, used, free etc. sizes from top command.
But I can't figure out which process uses swap, is it possible to find out swap memory by process?

I'm running CentOS 6.3.

-1

You could use ps and some quick awk maths to gain the answer.

The command that you can use is this...

$ ps -eo rss,vsz,pid,cmd | awk '{print $2-$1,$0}' | sort -nr | head

The first column out the output should be the swap usage.

rss / resident set size

resident set size, the non-swapped physical memory that a task has used (inkiloBytes). (alias rssize, rsz).

vsz / virtual memory size

virtual memory size, the process in KiB (1024-byte units). Device mappings are currently excluded; this is subject to change.

Awk maths

If rss (Column 1) is the non swapped memory and vsz(Column 2) is the physical memory, then..

swap = vsz - rss 
| improve this answer | |
  • 2
    No... the virtual memory size also considers the size of shared libraries, the executable itself, mapped memory areas (could be files mmap(2)-ed), ... – vonbrand Feb 7 '13 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.