Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

You can use the ps command to get the virtual memory size and the resident memory size of a process:

$ ps aux | grep apache2
www-data 31141  0.0  0.3 163864 24008 ?        S    16:15   0:01 /usr/sbin/apache2 -k start

Now virtual memory and resident memory doesn't provide accurate precision of a process's true memory footprint, because it also factors in shared libraries.

So a better solution is to use pmap to get the true memory usage of a process. So here is the output of pmap using the same process as above:

$ sudo pmap -d 31141
31141:   /usr/sbin/apache2 -k start
Address           Kbytes Mode  Offset           Device    Mapping
00007f85bbb82000      28 r-x-- 0000000000000000 0fc:00000 libnss_dns-2.15.so
mapped: 163864K    writeable/private: 28420K    shared: 592K

So the "writable/private" value is the private memory of the process, which is almost 28 mb. My question: Is this private memory only main memory (RAM) or does this number also include swap space possibly?

share|improve this question
up vote 1 down vote accepted

I found this post titled: Understanding memory usage on Linux which I think does a better job than the one I'd found previously on the linuxquestions.org site, titled: How to accurately measure memory usage?.

excerpt from the Understanding memory ... post

ps output
dbunker   3468  0.0  2.7  25400 14452 ?        S    20:19   0:00 kdeinit: kedit
pmap output
Address   Kbytes Mode  Offset           Device    Mapping
08048000      40 r-x-- 0000000000000000 0fe:00000 kdeinit
08052000       4 rw--- 0000000000009000 0fe:00000 kdeinit
08053000    1164 rw--- 0000000008053000 000:00000   [ anon ]
40000000      84 r-x-- 0000000000000000 0fe:00000 ld-2.3.5.so
40015000       8 rw--- 0000000000014000 0fe:00000 ld-2.3.5.so
40017000       4 rw--- 0000000040017000 000:00000   [ anon ]
... (trimmed) ...
mapped: 25404K    writeable/private: 2432K    shared: 0K
description of what's going on

If you go through the output, you will find that the lines with the largest Kbytes number are usually the code segments of the included shared libraries (the ones that start with "lib" are the shared libraries). What is great about that is that they are the ones that can be shared between processes. If you factor out all of the parts that are shared between processes, you end up with the "writeable/private" total, which is shown at the bottom of the output. This is what can be considered the incremental cost of this process, factoring out the shared libraries. Therefore, the cost to run this instance of KEdit (assuming that all of the shared libraries were already loaded) is around 2 megabytes. That is quite a different story from the 14 or 25 megabytes that ps reported.

How much swap is process X using?

You can find out a processes' swap space that it's using with this command:

$ grep VmSwap /proc/$(pidof chrome | awk '{print $1}')/status
VmSwap:     1324 kB

The above is getting the first PID of chrome returning the VmSwap value for it.


You might want to check out this tool instead if you're looking for accurate measures of memory, it's callled memstat:

There's a tutorial on cyberciti.biz titled: Linux: Find Out What’s Using Up All Virtual Memory that shows memstat in action.


share|improve this answer
Private resident size would be the size of memory the process is using on main memory, excluding any shared libraries. But not sure what is meant by "mapped total". – JohnMerlino Jul 12 '13 at 22:24
@JohnMerlino - let me know if the updates make more sense. The previous version of the answer was too vague. – slm Jul 13 '13 at 0:19
"This is what can be considered the incremental cost of this process, factoring out the shared libraries." But that doesn't tell me what percentage of that incremental cost is residant memory and disk memory. – JohnMerlino Jul 13 '13 at 17:35
@JohnMerlino - when you say disk memory you're talking about swap? – slm Jul 13 '13 at 17:44
I think you might have to calculate that manually. You can get a processes VmSwap that it's using with this command: grep VmSwap /proc/$(pidof chrome | awk '{print $1}')/status: VmSwap: 1324 kB – slm Jul 13 '13 at 17:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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