Linux find the memory used by a program / process using pmap command
You can find the memory used by a program (process) by looking into /proc directory or using standard command such as ps or top. However, you must calculate all memory usage by hand i.e. add Shared Memory + mapped file + total virtual memory size of the process + Resident Set Size + non-swapped physical memory used by process.
So how do you find the memory used by a process or program under Linux? Use a tool called pmap. It reports the memory map of a process or processes.
pmap examples
To display process mappings, type
$ pmap pid
$ pmap 3724
Output:
3724: /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf 0000000000400000 164K r-x-- /usr/sbin/lighttpd 0000000000629000 12K rw--- /usr/sbin/lighttpd 000000000bb6b000 4240K rw--- [ anon ] 00000035ee600000 104K r-x-- /lib64/ld-2.5.so 00000035ee819000 4K r---- /lib64/ld-2.5.so 00000035ee81a000 4K rw--- /lib64/ld-2.5.so 00000035eea00000 1304K r-x-- /lib64/libc-2.5.so 00000035eeb46000 2048K ----- /lib64/libc-2.5.so 00000035eed46000 16K r---- /lib64/libc-2.5.so 00000035eed4a000 4K rw--- /lib64/libc-2.5.so 00000035eed4b000 20K rw--- [ anon ] 00000035eee00000 8K r-x-- /lib64/libdl-2.5.so 00000035eee02000 2048K ----- /lib64/libdl-2.5.so ..... .... 00002aaaac51e000 4K r---- /lib64/libnss_files-2.5.so 00002aaaac51f000 4K rw--- /lib64/libnss_files-2.5.so 00007fff7143b000 84K rw--- [ stack ] ffffffffff600000 8192K ----- [ anon ] total 75180K
The -x option can be used to provide information about the memory allocation and mapping types per mapping. The amount of resident, non-shared anonymous, and locked memory is shown for each mapping:
pmap -x 3526
Output:
3526: -bash Address Kbytes RSS Anon Locked Mode Mapping 0000000000400000 700 - - - r-x-- bash 00000000006ae000 40 - - - rw--- bash 00000000006b8000 20 - - - rw--- [ anon ] 00000000008b7000 32 - - - rw--- bash 00000000098de000 536 - - - rw--- [ anon ] 00000035ee600000 104 - - - r-x-- ld-2.5.so 00000035ee819000 4 - - - r---- ld-2.5.so 00000035ee81a000 4 - - - rw--- ld-2.5.so 00000035eea00000 1304 - - - r-x-- libc-2.5.so 00000035eeb46000 2048 - - - ----- libc-2.5.so 00000035eed46000 16 - - - r---- libc-2.5.so 00000035eed4a000 4 - - - rw--- libc-2.5.so 00000035eed4b000 20 - - - rw--- [ anon ] 00000035eee00000 8 - - - r-x-- libdl-2.5.so 00000035eee02000 2048 - - - ----- libdl-2.5.so 00000035ef002000 4 - - - r---- libdl-2.5.so 00000035ef003000 4 - - - rw--- libdl-2.5.so 00000035ef600000 12 - - - r-x-- libtermcap.so.2.0.8 00000035ef603000 2044 - - - ----- libtermcap.so.2.0.8 00000035ef802000 4 - - - rw--- libtermcap.so.2.0.8 00002aaaaaaab000 4 - - - rw--- [ anon ] 00002aaaaaaba000 12 - - - rw--- [ anon ] 00002aaaaaabd000 40 - - - r-x-- libnss_files-2.5.so 00002aaaaaac7000 2044 - - - ----- libnss_files-2.5.so 00002aaaaacc6000 4 - - - r---- libnss_files-2.5.so 00002aaaaacc7000 4 - - - rw--- libnss_files-2.5.so 00002aaaaacc8000 55112 - - - r---- locale-archive 00002aaaae29a000 28 - - - r--s- gconv-modules.cache 00002aaaae2a1000 8 - - - rw--- [ anon ] 00007fff9bff4000 92 - - - rw--- [ stack ] ffffffffff600000 8192 - - - ----- [ anon ] ---------------- ------ ------ ------ ------ total kB 74496 - - -
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates.
You can Email this page to a friend.
You may also be interested in...
- Linux server memory check
- How do I monitor Linux/BSD system over time without scrolling output?
- Boost Linux desktop performance by reducing memory footprint
- nixCraft FAQ Roundup
- Howto share application data using UNIX System V IPC mechanisms
Discussion on This Article:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: find memory used by program, memory allocation, memory usage, physical memory, pmap_command, procps, shared memory, virtual memory size ~ Last updated on: November 20, 2007



-x option not found in redhat
Manoj,
You must be using older version update procps package.
I believe what you are saying is you need to first establish the PID and then use pmap. I found a command ps -C syslogd -o pid=firefox that can be used to find memory usage of firefox and thought I’d pass it along.
P.S. the pmap -x perameter works in Ubuntu
You must be root to use that command.
It works on ubuntu if you sudo pmap -x pid.
Linux version 2.6.9-55.0.9.ELsmp (brewbuilder@hs20-bc1-7.build.redhat.com) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)) #1 SMP Tue Sep 25 02:17:24 EDT 2007
Usage: pmap [-x | -d] [-q] pid…
-x show details
-d show offset and device number
-q quiet; less header/footer info
-V show the version number
pmap -v exists in RHEL4
pmap -x is what I meant.
thanks a lot for helping me.
hi!
every thing seems good, but how to calculate memory used and how top commnad and free are showing memory used, how they are calculating and showing the information.
thanks and regards
siva