pmap Command in Linux



The pmap command in Linux reports the memory map of a process. It provides detailed information about the memory usage of a process, including its stack, heap, shared libraries, and mapped files. This tool is helpful for debugging memory issues or analyzing how a process is utilizing memory.

Table of Contents

Here is a comprehensive guide to the options available with the pmap command −

Syntax of pmap Command

The syntax of the Linux pmap command is as follows −

pmap [options] [pids...] 

In the above syntax, the [options] field is used to specify options such as displaying extended format, command version, and others. The [pids...] field is used to specify the PIDs of one or more processes.

pmap Command Options

The options of the pmap command are listed below −

Flags Options Description
-x --extended Displays an extended format with detailed memory usage statistics
-d --device Shows device mappings for memory regions
-q --quiet Suppresses header and footer lines in the output
-A low,high --range low,high Limits results to memory regions within a specified address range
-X Displays more detailed information than the -x option, using /proc/PID/smaps
-XX Shows all available memory details provided by the kernel
-p --show-path Displays the full path of files in the mapping column
-c --read-rc Reads the default configuration for pmap
-C file --read-rc-from file Reads the configuration from a specified file
-n --create-rc Creates a new default configuration for pmap
-N file --create-rc-to file Creates a new configuration file at the specified location
-h --help Displays help text and exits
-V --version Displays version information and exits

Examples of pmap Command in Linux

This section demonstrates the usage of the pmap command in Linux with examples −

Displaying Memory Map of a Process

To display the memory map of a process, use the pmap command with the process ID. For example

pmap 2473
pmap Command in Linux1

To list the process and their process IDs, use the top or htop commands.

Note − Root privileges may be required for certain PIDs.

Displaying Extended Memory Map of a Process

To display the detailed memory map of a process, use the -x or --extended option with the pmap command −

pmap -x 2473
pmap Command in Linux2

Displaying Memory Map of a Process with Associated Device

To display memory mappings of a process with associated device information, use the -d or --device option −

pmap -d 2473
pmap Command in Linux3

Suppressing Headers and Footers

To suppress the header and footer while displaying the memory map, use the -q or --quiet option with the pmap command −

pmap -q 2473

Displaying Memory Map of a Process with Full Path of Files

To display the full path of the files in the mapping column, use the -p or --show-path option −

pmap -p 2473
pmap Command in Linux4

Displaying Detailed Memory Map of a Process

To display detailed memory mapping, use the -X option with pmap in the following way −

pmap -X 2473

The -X option gives more detailed information than the -x option, using /proc/PID/smaps. On the other hand, to get the available memory details provided by the kernel, use the -XX option −

pmap -XX 2473

These options are useful for debugging purposes.

Displaying Detailed Memory Map with a Specific Address Range

Limit the output to a specified memory address range using the -A or --range option.

pmap -A 000e6bf46fbf000,0000e6bf47000c000 2473
pmap Command in Linux5

Displaying Usage Help

To display the usage help of the pmap command, use the -h or --help option −

pmap -h

Conclusion

The pmap command in Linux is a powerful utility for analyzing the memory usage of processes, offering detailed insights into components like stack, heap, shared libraries, and mapped files. It supports various options to display extended formats, device mappings, address range limitations, and more.

The pmap command is useful for debugging memory issues and understanding memory utilization in Linux environments.

Advertisements