How to View a Process Memory Map Using the pmap Command in Linux

When a background daemon or a memory-intensive application (like a database server or a Java virtual machine) begins consuming excessive amounts of RAM on a Linux system, administrators must investigate the memory leak immediately. While tools like top and htop can tell you the total percentage of memory a process is consuming, they cannot tell you how that memory is being used. To see a detailed, granular breakdown of exactly which shared libraries, stacks, and heap allocations are consuming a specific process’s RAM, you must use the pmap command.

How the pmap Command Works

The pmap utility connects directly to the kernel and reads the memory map configuration for a specific, actively running process. It outputs a highly detailed list showing every single contiguous block of memory the process has requested from the operating system, the exact size of that block in kilobytes, and the specific file or library that is occupying that memory space.

Finding the Process ID

Because pmap targets a specific running application, you must know the Process ID (PID) of the application before you can run the command. You can find the PID using the pgrep command. For example, to find the PID of your MySQL database:

pgrep mysql

Displaying the Memory Map

Once you have the PID (e.g., 1455), you simply pass it to the pmap command.

pmap 1455

The output will be a long table containing three columns. From left to right, you will see:

  1. Memory Address: The exact hexadecimal starting address of the memory block.
  2. Size: The size of the memory allocation in Kilobytes (e.g., 2048K).
  3. Mapping: The name of the shared library (e.g., libc-2.31.so), the stack, or the anon (anonymous) memory heap occupying that space.

At the very bottom of the output, pmap will print a summary line detailing the absolute total amount of memory currently mapped to the process.

Using the Extended Format (The -x Flag)

The default output of pmap is helpful, but it can be slightly misleading. It shows the total amount of memory the process has requested from the OS (virtual memory), not necessarily the amount of physical RAM it is actively using at this exact moment. To see the physical RAM consumption, you must use the -x (extended) flag.

pmap -x 1455

This command adds two critical new columns to the output:

  • RSS (Resident Set Size): This is the most important metric. It shows exactly how many kilobytes of physical hardware RAM that specific memory block is currently consuming.
  • Dirty: This shows how much of that memory has been modified by the application and must be written back to the disk before the memory block can be freed. High dirty memory counts often point directly to the source of a memory leak.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.