LinuxCommandLibrary

pmap

Report memory map of a process

TLDR

Print memory map for a specific process ID (PID)

$ pmap [pid]
copy

Show the extended format
$ pmap --extended [pid]
copy

Show the device format
$ pmap --device [pid]
copy

Limit results to a memory address range specified by low and high
$ pmap --range [low],[high]
copy

Print memory maps for multiple processes
$ pmap [pid1 pid2 ...]
copy

SYNOPSIS

pmap [ options ] PID [ PID ... ]
pmap -V
pmap -h

PARAMETERS

-x
    Extended format. Shows additional columns like Resident Set Size (RSS), Dirty pages, and the full path to the mapped file. This is often the most useful output for detailed memory analysis.

-d
    Device format. Displays columns for device major:minor and inode number, providing details about the underlying file system object that corresponds to the memory region.

-q
    Quiet mode. Suppresses the header and footer lines from the output, showing only the memory map entries. This is particularly useful when scripting or processing the output programmatically.

-p
    Show PID. When multiple process IDs are provided as arguments, this option ensures that each block of output is clearly prefixed with the corresponding PID, making it easier to distinguish between process maps.

-V
    Version information. Prints the version of the pmap utility to standard output and then exits.

-h
    Help message. Displays a brief help message explaining command usage and available options, then exits.

DESCRIPTION

pmap (process memory map) is a Linux utility that reports the memory address space of a running process. It displays a detailed breakdown of the process's virtual memory regions, including their start and end addresses, permissions (read, write, execute), offset within the mapped file, device information (major:minor), inode number, and the path to the file or library being mapped (e.g., shared libraries, executables, anonymous memory). The command is invaluable for debugging memory-related issues, analyzing memory consumption, understanding how shared libraries are loaded, and identifying potential memory leaks. It provides a human-readable representation of the data found in /proc/<pid>/maps and /proc/<pid>/smaps, offering insights into how a process utilizes its RAM and virtual memory. Users can see private and shared memory usage, total resident set size (RSS), and other critical memory metrics.

CAVEATS

pmap requires appropriate permissions to inspect a process. For processes not owned by the current user, sudo or root privileges might be necessary, depending on the system's kernel.yama.ptrace_scope setting. The output provides a snapshot of memory usage at the time of execution; memory maps can change dynamically for a running process. The reported sizes (like RSS) might differ slightly from other tools due to how memory regions are counted and reported. For very large processes with many memory regions, the output can be extensive.

UNDERSTANDING PMAP OUTPUT

The pmap output columns typically include:
Address: The starting virtual memory address of the region.
Kbytes: The size of the region in kilobytes.
RSS (Resident Set Size): The portion of the process's memory that is currently held in RAM (not swapped out).
Dirty: Memory pages that have been modified (written to) and haven't been written back to disk yet.
Mode: Permissions for the memory region (r=read, w=write, x=execute, s=shared, p=private).
Mapping: The file or device mapped into this region, or special tags like [heap], [stack], [anon] (anonymous memory), or [vdso].
The pmap -x option provides the most detailed view, including RSS and Dirty pages, which are crucial for understanding actual memory consumption. The data presented by pmap is primarily sourced from the kernel's /proc/<pid>/maps and /proc/<pid>/smaps files.

HISTORY

pmap is a long-standing utility in the Linux ecosystem, typically part of the procps or procps-ng package. Its core functionality dates back to early Linux kernels, providing a user-friendly interface to the information exposed by the /proc filesystem, specifically /proc/<pid>/maps. As the /proc filesystem evolved to include more detailed memory information like /proc/<pid>/smaps (which distinguishes between private and shared memory usage), pmap adapted, with its -x (extended) option now often leveraging this richer data to provide more comprehensive memory statistics like Resident Set Size (RSS) and Dirty pages. Its development tracks the kernel's capabilities for exposing process memory details.

SEE ALSO

ps(1), top(1), free(1), proc(5)

Copied to clipboard