$_ CLI In Depth
Learning progress 0%
lesson syscalls namespaces cgroups

Memory Maps: /proc/PID/maps

6 min read Module 17: Syscalls, Namespaces & cgroups Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:15

Virtual addresses and regions

Programs use virtual addresses. The kernel and the processor translate those addresses into physical memory pages, and the translation is set per process. The address space is not one block. It is a list of regions, each with a start, an end, and a set of rights. A region might hold the program code, a writable data segment, the heap that malloc grows, the stack for function calls, or a file that was mapped with mmap.

The kernel calls each region a virtual memory area. It stores them in a sorted structure and checks every memory access against them. An access outside every region produces a segmentation fault, and an access that breaks the rights of its region, such as a write to read-only code, does the same.

Reading the map

The file /proc/PID/maps prints one line per region. A typical line has six fields: the address range, the permissions, the offset into the backing file, the device, the inode number, and the pathname. The permissions are four characters: read, write, execute, and either p for private or s for shared. Regions with no pathname are anonymous memory, and special labels such as [heap], [stack], and [vdso] name the others.

BASH1 lines
cat /proc/self/maps > maps.txt; head -n 5 maps.txt

The first lines are usually the program code, which has permissions like r-xp. It is readable and executable, but not writable, which protects code from being changed while it runs. Later lines show data and the loader.

Shared libraries are just mappings

A dynamically linked program does not contain the code of the C library. At startup, the dynamic loader maps each shared library file into the address space, and the regions show the library paths in the last field. The library code is mapped with execute permission, and its data is private to the process, which is why a library file can be shared by many processes without copying the code into memory for each one.

On the lab machine the C library is musl, the one that Alpine Linux uses, so the loader and library names contain musl. Filter for the suffix .so to see them.

BASH1 lines
awk '{print $6}' maps.txt | grep / | sort -u | grep '[.]so'

The awk command prints the sixth field, grep keeps lines that contain a slash, sort removes duplicates, and the final grep keeps the shared objects. The list is short because each library appears once even if it has several regions.

The stack and the heap

The stack is marked with [stack]. It grows downward and holds return addresses and local variables for each function call. The heap is marked [heap] on many programs, and it grows upward as malloc asks for more memory with brk or mmap. Large allocations often get their own anonymous mapping instead of extending the heap.

Reading the lines for these regions tells you whether memory is growing in the heap or in separate mappings, which matters when a program slowly uses more memory over time.

Note

The pathnames in maps are the paths the file had when it was mapped. A file that was deleted after mapping shows "(deleted)" at the end of its line, and its memory stays in use until the process exits.

Counting and comparing

Counting executable regions with awk is a quick way to see how much code a program maps. Comparing two maps from different moments shows growth: a region whose range gets larger is a region that was extended. The format is stable enough that small awk scripts work across kernels, which is the reason the lab asks for these fields.

For a summary of memory use per process, the VmRSS and VmSize lines of the status file are easier to read than a full map.

Address space layout randomization

Each time a program starts, the kernel can place the stack, the heap, and the libraries at random addresses. This randomization makes it harder for an attacker to predict where code lives. The addresses in the map therefore differ from run to run, which is why the lab checks pathnames and permissions rather than addresses. A check that compared addresses would pass once and fail the next time.

Randomization does not change permissions or labels. A region named stack is a stack on every run, and a line with r-xp is code on every run. When you compare maps across runs, compare the pathnames and the permissions, and ignore the first field.

When a region grows

The heap grows when malloc needs more room, and the kernel grants it either by moving the program break or by creating a new mapping. A program that allocates many small pieces extends its heap region, while a single large allocation usually gets a region of its own. Taking two maps during a run shows which of these happened, and the line whose range got larger tells you where the memory went.

Reading the permissions column

The permission field is the fastest way to classify a region. A region with r-x and p is code that the loader mapped from a file, and it should never be writable. A region with rw and p is private data, such as the data segment or the heap, and it can change but is not visible to other processes. A region with s is shared, which means that writes are visible to any process that maps the same object, and shared memory is how some programs pass large data without copying it. A region with no permission bits at all, written as ---p, is reserved space that is not yet usable, which is common for guard pages that catch overflows.

Reading the field from top to bottom gives a quick picture of a program. Code comes first, then data, then the heap and the libraries, and the stack sits near the top of the user space. Most programs follow that order, so a region that breaks it is worth a second look.

Inside a process: its file table and its memory

Visualizer

Every process keeps a table of open files and a map of its memory. Both are visible as plain files under /proc, so you can read what the kernel knows about a running shell.

1 / 3
fd table of this shell
0/dev/pts/0 (stdin)
1/dev/pts/0 (stdout)
2/dev/pts/0 (stderr)

Each process has an fd table: a small array of numbers, each pointing at an open file. In a terminal session, the first three are inherited: 0 for input, 1 for output, 2 for errors.

exec 3< /etc/hostname; ls -l /proc/$$/fd; exec 3<&-
Terminal lab · 3 steps · real Linux in your browser

Read the memory map of a process

Save /proc/self/maps, find the shared libraries it lists, and count the executable regions.

01
Save the memory map
Each line of /proc/PID/maps is one virtual memory area. The fields are the address range, the permissions, the offset, the device, the inode, and the path. Save the map of cat: ``bash cat /proc/self/maps > maps.txt `` Open maps.txt and find a line with r-xp, which is readable and executable code, and a line for [stack].
Show hint for step 1
The permission field has four characters: read, write, execute, and private or shared. The label [stack] marks the stack.
02
Find the shared libraries
The sixth field of each line is the path of the file that is mapped. Keep the unique paths that contain a slash and then keep the ones that name a shared object: ``bash cat /proc/self/maps > maps.txt awk '{print $6}' maps.txt | grep / | sort -u > files.txt grep '[.]so' files.txt `` The lines that the last grep prints are shared libraries. Write the list to files.txt and confirm it is not empty.
Show hint for step 2
awk prints the sixth field. Shared libraries end in .so, possibly followed by a version number.
03
Count the executable regions
Count the lines in maps.txt whose permission field contains x. Save the count to exec-regions.txt: ``bash cat /proc/self/maps > maps.txt awk '$2 ~ /x/' maps.txt | wc -l > exec-regions.txt `` Open exec-regions.txt. The number should be at least 1.
Show hint for step 3
The second field is the permission string. The pattern /x/ matches any line where that field contains the letter x.
Check yourself Question 1 of 4
Concept Check Reading the permission field recall

In /proc/PID/maps, what does the permission field r-xp mean?

Recap & Key Takeaways

A process address space is a list of virtual memory areas, each with an address range, permissions, and a pathname or label.
/proc/PID/maps has six fields per line, with permissions such as r-xp for readable and executable code.
Shared libraries appear as mappings of their files, so a library is shared by many processes without copying its code.
The [stack] and [heap] labels mark the regions that grow during function calls and allocations.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue