Linux Command Reference ยท Special Files and Directories
The /proc/PID directory
Reference for /proc/PID: cmdline, environ, status, fd, cwd, exe, maps and more, with how to read each file, NUL separators, permissions and /proc/self.
Every running process has a directory /proc/<PID> that the kernel creates on the fly. Its files and links show the command line, environment, open files, memory use, working directory and more, without any special tool. ps, top, lsof and pidof are built on exactly this data. The special name /proc/self always points to the process that opens it, so a script can inspect itself.
The directory disappears when the process ends, so reads can fail with "No such file or directory" if the process exits between listing and reading. Most entries of other users' processes are restricted.
ls /proc/$$ cat /proc/$$/status
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
Useful entries (all under /proc/PID/):
| Entry | Description |
|---|---|
cmdline |
Arguments, separated by NUL bytes. Empty for kernel threads and zombies. |
environ |
Environment at the start of the process, NUL separated. Not updated by later export. |
status |
Human-readable summary: Name, State, Pid, PPid, Uid, Threads, VmRSS, VmSize. |
stat, statm |
Machine-readable numbers (used by ps). |
cwd, exe, root |
Symlinks to the working directory, the program file and the root directory. |
fd/ |
One symlink per open descriptor: 0, 1, 2 and the rest. |
fdinfo/ |
Position and flags of each descriptor. |
maps, smaps |
Memory mappings, and detail per mapping. |
limits |
Current resource limits (open files, processes, core size). |
io |
Bytes read and written. |
task/ |
One subdirectory per thread. |
cgroup, ns/ |
Control group membership and namespace links (containers). |
Errors: Permission denied for processes of other users (environ, fd, maps) unless you are root; No such file or directory when the process has ended.
Usage notes
- NUL separators: use
tr '\0' ' 'orxargs -0to readcmdlineandenviron. A plaincatruns the words together. - Find a deleted open file:
ls -l /proc/PID/fdshows(deleted)for files unlinked while open; you can still copy their content withcp /proc/PID/fd/N saved. - Zombies: state
Z; the entry exists, butcmdlineis empty. The parent mustwait()for it. See jobs and processes. - Race conditions: a PID can be reused. For scripts, test the directory and read quickly, or hold a descriptor to it.
- Threads appear in
task/and have their own IDs, which also work as/proc/TID. - Hardened systems mount
/procwithhidepid=2, so users see only their own processes. - Tools:
ps -o pid,ppid,stat,cmd,pidof,lsof -p PIDgive nicer output of the same data.