Skip to content

Using Pmap to Report Memory Map of a Process (With Examples)

February 3, 2024

pmap is a Linux command-line utility that reports the memory map of a process, displaying information about the memory regions allocated by the process. It provides insights into the memory usage and helps diagnose issues related to memory management. Here are some examples of how to use pmap:

Basic Usage:

To use pmap, you need to know the process ID (PID) of the target process. You can find the PID using tools like ps or pgrep. Here’s a basic example:

pmap <PID>

Replace <PID> with the actual process ID.

Example:

pmap 12345

This command will display the memory map for the process with PID 12345.

Options and Output:

pmap provides various options to customize the output. Here are some commonly used options:

  • Display detailed information:
  pmap -x <PID>

This option provides more detailed information, including the memory permissions, offset, device, and inode.

  • Sort by address:
  pmap -S <PID>

This option sorts the memory map by address, making it easier to analyze contiguous memory regions.

  • Display in KB instead of MB:
  pmap -K <PID>

This option displays memory sizes in kilobytes instead of the default megabytes.

Examples:

  1. Basic pmap Output:
   pmap 12345

This command provides a summary of the memory map for the process with PID 12345.

  1. Detailed Output:
   pmap -x 12345

This command provides a more detailed output, including memory permissions, offset, device, and inode.

  1. Sort by Address:
   pmap -S 12345

This command sorts the memory map by address.

  1. Display in KB:
   pmap -K 12345

This command displays memory sizes in kilobytes instead of megabytes.

Understanding the Output:

The output of pmap consists of several columns, including:

  • Address: The starting address of the memory region.
  • Kbytes: The size of the memory region in kilobytes.
  • RSS: The resident set size, indicating the portion of the memory that is held in RAM.
  • Dirty: The amount of memory that has been modified and needs to be written to disk.
  • Mode: The access permissions for the memory region (e.g., read, write, execute).

Reviewing the pmap output can help identify memory usage patterns, identify memory leaks, and troubleshoot issues related to memory management in a specific process.

Note: Some Linux distributions may require elevated privileges (root or sudo) to use pmap on processes owned by other users.

Keep in mind that the examples provided are basic, and you can explore more options in the pmap manual (man pmap) for further customization based on your specific requirements.