Fundamentals 5 min read

Unlocking Linux /proc: How to Inspect Process Information with /proc/self

This guide explains the Linux /proc virtual file system, details the special role of /proc/self for accessing the current process's data, and provides command examples for retrieving cmdline, cwd, exe, environ, maps, and mem information.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Unlocking Linux /proc: How to Inspect Process Information with /proc/self

/proc Overview

The /proc directory is a virtual (pseudo) file system that resides in memory and exposes the kernel's runtime state. It contains a collection of special files that let users view hardware details, process information, and even modify certain kernel parameters.

Each numeric subdirectory under /proc corresponds to a running process ID (PID) and holds files describing that process.

/proc/self Explained

/proc/self

is a shortcut that always points to the directory of the calling process, effectively equivalent to /proc/<pid> where <pid> is the current process's PID. This eliminates the need to look up the PID before accessing process-specific files.

Practical Commands Using /proc/self

cmdline

Retrieve the full command line used to start the current process:

cat /proc/self/cmdline

cwd

Show the symbolic link to the current working directory of the process:

ls /proc/self/cwd

exe

Display the absolute path of the executable binary of the process:

ls -al /proc/self/exe

environ

List all environment variables of the process:

cat /proc/self/environ

maps

Show the memory mapping of the process, including address ranges, permissions, offsets, device numbers, inode, and associated file paths: cat /proc/self/maps Each line follows the format: address‑range permissions offset dev inode pathname . For example, /usr/bin/cat indicates a mapped binary.

mem

The /proc/self/mem file represents the process's memory image. Direct reads are restricted; to extract data you must combine the offsets from /proc/self/maps with appropriate start and end parameters.

Note: Attempting to read unmapped regions will fail.

Key Takeaways

/proc

provides a read‑only view of kernel and process state without requiring special privileges. /proc/self simplifies accessing information about the current process.

Common files ( cmdline, cwd, exe, environ, maps, mem) are useful for debugging, monitoring, and forensic analysis.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxsystem-monitoringprocVirtual File Systemprocess introspection
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.