Skip to content

Linux Foundations / Manage a Linux host ยท Step 31 of 50

Lesson: The /proc filesystemSwitch
โ† Linux Foundations

System administration

The /proc filesystem

Explore the virtual files where the kernel exposes process and system information.

/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.

bash
$ findmnt /proc
TARGET SOURCE FSTYPE OPTIONS
/proc  proc   proc   rw,nosuid,nodev,noexec,relatime

One directory per process

Each numbered directory is a process, named after its PID. The link /proc/self points to whichever process is reading it.

bash
$ ls /proc
1  2  778  2145  cpuinfo  loadavg  meminfo  self  uptime  version ...

Useful entries inside /proc/PID/:

  • status: readable summary of state, IDs and memory
  • cmdline: the command line arguments
  • cwd: link to the working directory
  • exe: link to the program file
  • fd/: links for the open file descriptors
  • environ: environment variables as they were at start
bash
$ grep -E '^(Name|State|PPid|VmRSS)' /proc/$$/status
Name:	bash
State:	S (sleeping)
PPid:	2144
VmRSS:	    5320 kB

The arguments in cmdline are separated by NUL bytes, not spaces, so they look glued together. Translate them:

bash
$ tr '\0' ' ' < /proc/$$/cmdline; echo
-bash

System-wide files

bash
$ 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.