Linux pmap Command Tutorial for Beginners (5 Examples)

Linux command line offers a lot of tools that help you know more about processes that are currently active in your system. One such utility is pmap, which reports the process memory map. In this tutorial, we will discuss the basics of pmap using some easy to understand examples.

But before we do that, it's worth mentioning all examples here have been tested on an Ubuntu 18.04 LTS machine.

Linux pmap command

The pmap command in Linux lets you see the memory map of one or more than one processes. Following is its syntax:

pmap [options] pid [...]

And here's how the tool's man page explains it:

The pmap command reports the memory map of a process or processes.

Following are some Q&A-styled examples that should give you an even better idea on how the pmap command works.

Q1. How to use pmap?

Basic usage is simple. Just execute the 'pmap' command without any option. Of course, you need to pass a process PID as input.

For example, I used pmap in the following way:

pmap 5146

And here's a part of output that was produced:

5146:   gedit
000055bde4835000      8K r-x-- gedit
000055bde4a36000      4K r---- gedit
000055bde4a37000      4K rw--- gedit
000055bde5d32000  13944K rw---   [ anon ]
00007fc910000000    132K rw---   [ anon ]
00007fc910021000  65404K -----   [ anon ]
00007fc918000000    896K rw---   [ anon ]
00007fc9180e0000  64640K -----   [ anon ]
00007fc91c750000    204K r---- UbuntuMono-R.ttf
00007fc91c783000    644K r-x-- libaspell.so.15.2.0
00007fc91c824000   2048K ----- libaspell.so.15.2.0
00007fc91ca24000     20K r---- libaspell.so.15.2.0
00007fc91ca29000      4K rw--- libaspell.so.15.2.0
00007fc91ca2a000      8K r-x-- libenchant_aspell.so
00007fc91ca2c000   2044K ----- libenchant_aspell.so
00007fc91cc2b000      4K r---- libenchant_aspell.so
00007fc91cc2c000      4K rw--- libenchant_aspell.so
00007fc91cc2d000     44K r-x-- libenchant_hspell.so
00007fc91cc38000   2044K ----- libenchant_hspell.so
00007fc91ce37000      4K r---- libenchant_hspell.so
00007fc91ce38000     12K rw--- libenchant_hspell.so
00007fc91ce3b000    428K r-x-- libhunspell-1.6.so.0.0.1
00007fc91cea6000   2044K ----- libhunspell-1.6.so.0.0.1
00007fc91d0a5000      4K r---- libhunspell-1.6.so.0.0.1
00007fc91d0a6000     16K rw--- libhunspell-1.6.so.0.0.1
00007fc91d0aa000     16K r-x-- libenchant_myspell.so
00007fc91d0ae000   2048K ----- libenchant_myspell.so
00007fc91d2ae000      4K r---- libenchant_myspell.so
...
...
...

So there you go, the output first shows you the name of the process and then follows it up with the memory map.

Q2. How make pmap show extended output?

To make pmap show output in extended format, use the -x command line option. For example:

pmap -x 5146

Following is a part of the output produced:

5146:   gedit
Address           Kbytes     RSS   Dirty Mode  Mapping
000055bde4835000       8       4       0 r-x-- gedit
000055bde4835000       0       0       0 r-x-- gedit
000055bde4a36000       4       4       4 r---- gedit
000055bde4a36000       0       0       0 r---- gedit
000055bde4a37000       4       4       4 rw--- gedit
000055bde4a37000       0       0       0 rw--- gedit
000055bde5d32000   13944   13692   13692 rw---   [ anon ]
000055bde5d32000       0       0       0 rw---   [ anon ]
00007fc910000000     132      44      44 rw---   [ anon ]
00007fc910000000       0       0       0 rw---   [ anon ]
00007fc910021000   65404       0       0 -----   [ anon ]
00007fc910021000       0       0       0 -----   [ anon ]
00007fc918000000     896     896     896 rw---   [ anon ]
00007fc918000000       0       0       0 rw---   [ anon ]
00007fc9180e0000   64640       0       0 -----   [ anon ]
00007fc9180e0000       0       0       0 -----   [ anon ]
00007fc91c750000     204     136       0 r---- UbuntuMono-R.ttf
00007fc91c750000       0       0       0 r---- UbuntuMono-R.ttf
00007fc91c783000     644     472       0 r-x-- libaspell.so.15.2.0
00007fc91c783000       0       0       0 r-x-- libaspell.so.15.2.0
00007fc91c824000    2048       0       0 ----- libaspell.so.15.2.0
00007fc91c824000       0       0       0 ----- libaspell.so.15.2.0
00007fc91ca24000      20      20      20 r---- libaspell.so.15.2.0
00007fc91ca24000       0       0       0 r---- libaspell.so.15.2.0
00007fc91ca29000       4       4       4 rw--- libaspell.so.15.2.0
00007fc91ca29000       0       0       0 rw--- libaspell.so.15.2.0
00007fc91ca2a000       8       8       0 r-x-- libenchant_aspell.so
00007fc91ca2a000       0       0       0 r-x-- libenchant_aspell.so
00007fc91ca2c000    2044       0       0 ----- libenchant_aspell.so
00007fc91ca2c000       0       0       0 ----- libenchant_aspell.so
00007fc91cc2b000       4       4       4 r---- libenchant_aspell.so
00007fc91cc2b000       0       0       0 r---- libenchant_aspell.so
...
...
...

Note that if you need even more details, you can use the -X command line option.

Q3. How to make pmap show device format in output?

This can be done using the -d command line option. For example:

pmap -d 5146

And here's a part of the output produced:

5146:   gedit
Address           Kbytes Mode  Offset           Device    Mapping
000055bde4835000       8 r-x-- 0000000000000000 008:00008 gedit
000055bde4a36000       4 r---- 0000000000001000 008:00008 gedit
000055bde4a37000       4 rw--- 0000000000002000 008:00008 gedit
000055bde5d32000   13944 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910000000     132 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910021000   65404 ----- 0000000000000000 000:00000   [ anon ]
00007fc918000000     896 rw--- 0000000000000000 000:00000   [ anon ]
00007fc9180e0000   64640 ----- 0000000000000000 000:00000   [ anon ]
00007fc91c750000     204 r---- 0000000000000000 008:00008 UbuntuMono-R.ttf
00007fc91c783000     644 r-x-- 0000000000000000 008:00008 libaspell.so.15.2.0
00007fc91c824000    2048 ----- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca24000      20 r---- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca29000       4 rw--- 00000000000a6000 008:00008 libaspell.so.15.2.0
00007fc91ca2a000       8 r-x-- 0000000000000000 008:00008 libenchant_aspell.so
00007fc91ca2c000    2044 ----- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2b000       4 r---- 0000000000001000 008:00008 libenchant_aspell.so
00007fc91cc2c000       4 rw--- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2d000      44 r-x-- 0000000000000000 008:00008 libenchant_hspell.so
00007fc91cc38000    2044 ----- 000000000000b000 008:00008 libenchant_hspell.so
00007fc91ce37000       4 r---- 000000000000a000 008:00008 libenchant_hspell.so
00007fc91ce38000      12 rw--- 000000000000b000 008:00008 libenchant_hspell.so
...
...
...

So you can see a new column 'device' was added in the output.

Q4. How to strip pmap output of headers and footers?

If you don't want to see stuff like column names in the pmap output, you can use the -q command line option.

For example:

pmap -q -d 5146

Following was the output:

5146:   gedit
000055bde4835000       8 r-x-- 0000000000000000 008:00008 gedit
000055bde4a36000       4 r---- 0000000000001000 008:00008 gedit
000055bde4a37000       4 rw--- 0000000000002000 008:00008 gedit
000055bde5d32000   13944 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910000000     132 rw--- 0000000000000000 000:00000   [ anon ]
00007fc910021000   65404 ----- 0000000000000000 000:00000   [ anon ]
00007fc918000000     896 rw--- 0000000000000000 000:00000   [ anon ]
00007fc9180e0000   64640 ----- 0000000000000000 000:00000   [ anon ]
00007fc91c750000     204 r---- 0000000000000000 008:00008 UbuntuMono-R.ttf
00007fc91c783000     644 r-x-- 0000000000000000 008:00008 libaspell.so.15.2.0
00007fc91c824000    2048 ----- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca24000      20 r---- 00000000000a1000 008:00008 libaspell.so.15.2.0
00007fc91ca29000       4 rw--- 00000000000a6000 008:00008 libaspell.so.15.2.0
00007fc91ca2a000       8 r-x-- 0000000000000000 008:00008 libenchant_aspell.so
00007fc91ca2c000    2044 ----- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2b000       4 r---- 0000000000001000 008:00008 libenchant_aspell.so
00007fc91cc2c000       4 rw--- 0000000000002000 008:00008 libenchant_aspell.so
00007fc91cc2d000      44 r-x-- 0000000000000000 008:00008 libenchant_hspell.so
00007fc91cc38000    2044 ----- 000000000000b000 008:00008 libenchant_hspell.so
00007fc91ce37000       4 r---- 000000000000a000 008:00008 libenchant_hspell.so
00007fc91ce38000      12 rw--- 000000000000b000 008:00008 libenchant_hspell.so

So you can see the header was removed from the output.

Q5. How to make pmap show full paths in output?

In case you want pmap to show full path to files in the mapping column, you can use the -p command line option.

For example:

pmap -p 5146

And here's the output produced by this command:

5146:   gedit
000055bde4835000      8K r-x-- /usr/bin/gedit
000055bde4a36000      4K r---- /usr/bin/gedit
000055bde4a37000      4K rw--- /usr/bin/gedit
000055bde5d32000  13944K rw---   [ anon ]
00007fc910000000    132K rw---   [ anon ]
00007fc910021000  65404K -----   [ anon ]
00007fc918000000    896K rw---   [ anon ]
00007fc9180e0000  64640K -----   [ anon ]
00007fc91c750000    204K r---- /usr/share/fonts/truetype/ubuntu/UbuntuMono-R.ttf
00007fc91c783000    644K r-x-- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91c824000   2048K ----- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91ca24000     20K r---- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91ca29000      4K rw--- /usr/lib/x86_64-linux-gnu/libaspell.so.15.2.0
00007fc91ca2a000      8K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91ca2c000   2044K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91cc2b000      4K r---- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91cc2c000      4K rw--- /usr/lib/x86_64-linux-gnu/enchant/libenchant_aspell.so
00007fc91cc2d000     44K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91cc38000   2044K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91ce37000      4K r---- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91ce38000     12K rw--- /usr/lib/x86_64-linux-gnu/enchant/libenchant_hspell.so
00007fc91ce3b000    428K r-x-- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91cea6000   2044K ----- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91d0a5000      4K r---- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91d0a6000     16K rw--- /usr/lib/x86_64-linux-gnu/libhunspell-1.6.so.0.0.1
00007fc91d0aa000     16K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d0ae000   2048K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d2ae000      4K r---- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d2af000      4K rw--- /usr/lib/x86_64-linux-gnu/enchant/libenchant_myspell.so
00007fc91d2b0000     44K r-x-- /usr/lib/x86_64-linux-gnu/enchant/libenchant_ispell.so
00007fc91d2bb000   2048K ----- /usr/lib/x86_64-linux-gnu/enchant/libenchant_ispell.so

So you can see that file names with complete paths are produced in output.

Conclusion

If your work involves dealing with process memory maps, this tool is for you. In this tutorial, we have described the basic usage of this command. Once you're done practicing what all we've discussed here, head to the tool's man page to learn more about it.

Share this page:

Suggested articles

0 Comment(s)

Add comment