/proc looks like a directory full of files, but those files are not stored on disk. It is a virtual filesystem: the kernel generates the contents when you read them.
$ findmnt /proc
TARGET SOURCE FSTYPE OPTIONS
/proc proc proc rw,nosuid,nodev,noexec,relatimeOne directory per process
Each numbered directory is a process, named after its PID. The link /proc/self points to whichever process is reading it.
$ ls /proc
1 2 778 2145 cpuinfo loadavg meminfo self uptime version ...Useful entries inside /proc/PID/:
status: readable summary of state, IDs and memorycmdline: the command line argumentscwd: link to the working directoryexe: link to the program filefd/: links for the open file descriptorsenviron: environment variables as they were at start
$ grep -E '^(Name|State|PPid|VmRSS)' /proc/$$/status
Name: bash
State: S (sleeping)
PPid: 2144
VmRSS: 5320 kBThe arguments in cmdline are separated by NUL bytes, not spaces, so they look glued together. Translate them:
$ tr '\0' ' ' < /proc/$$/cmdline; echo
-bashSystem-wide files
$ cat /proc/loadavg
0.15 0.10 0.09 1/213 6402
$ head -3 /proc/meminfo
MemTotal: 8039212 kB
MemFree: 2210044 kB
MemAvailable: 5902316 kB/proc/cpuinfo describes the processors, and /proc/uptime gives seconds since boot. Tools such as ps, top and free get much of their data from /proc.
Access and writing
You can read much about other users' processes, but sensitive entries such as environ and fd are restricted to the owner and root. Some systems also hide other users' processes completely.
Files under /proc/sys/ hold kernel settings. Root can change them, usually with sysctl. A change made this way takes effect at once but is lost at reboot unless saved in a configuration file.
Try it
Start sleep 300 &, then explore its directory with ls -l /proc/PID/, using the real number. Follow cwd and exe with readlink. The processes and cron lab is a good playground, and the proc manual page documents the entries.
Check your understanding
The /proc filesystem
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.