Unlock Linux Secrets: Exploring /proc and /proc/self Virtual Files
This article explains the Linux /proc virtual filesystem, the special role of /proc/self for accessing the current process's information, and provides practical commands to read cmdline, cwd, exe, environ, maps, and mem files for system monitoring and debugging.
/proc Overview
/procis a virtual (pseudo) file system that stores a series of special files reflecting the kernel's current runtime state. Users can read these files to view hardware details and information about running processes, and even modify some to change kernel behavior. The /proc directory resides in memory and contains many sub‑directories named with numeric PIDs, each holding multiple information files for the corresponding process.
/proc/self Overview
/proc/selfrepresents the directory of the current process. Instead of first obtaining the PID and accessing /proc/<pid>, a process can directly read /proc/self to obtain its own system information, as the directory dynamically maps to the calling process's PID.
How to Use
cmdline
Retrieve the full command line used to start the current process. cat /proc/self/cmdline The command returns the startup command of the process.
cwd
The cwd file is a symbolic link pointing to the current working directory of the process.
ls /proc/self/cwdexe
Obtain the absolute path of the executable file of the current process.
ls -al /proc/self/exeenviron
Display the environment variable information of the current process.
cat /proc/self/environmaps
The /proc/self/maps file lists the memory mapping of the current process. Each line provides the memory region, permissions, offset, device number, inode, and path (e.g., /usr/bin/cat for a binary).
mem
The /proc/self/mem file contains the process's memory image. It cannot be read directly because some regions are unmapped; you must use the offset addresses from /proc/self/maps together with start and end parameters to read specific sections.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
