devutils/ATFQ/book ATFQ git

Part II · Your system

13.3 /proc and /sys

alsoproc/procsys/sysprocfssysfspseudo filesystem

TL;DR

  • Neither is on disk: the kernel makes up their content when you read it.
  • /proc: one folder per process (/proc/1234), plus system-wide files such as /proc/meminfo and /proc/cpuinfo.
  • /sys: devices and drivers, as a tree (/sys/block, /sys/class/net).
  • Some files can be written to change kernel settings live. That needs root, and the change is lost at reboot.
cat /proc/self/status     # the process reading it: cat itself
ls /sys/class/net         # your network interfaces

Pitfalls

Deep dive 2 questions

Why two of them?

/proc came first. Its idea, processes as files, comes from Unix research systems of the 1980s. On Linux it grew into a place for all kinds of kernel information, with no rules on what goes where.

/sys (sysfs) arrived with kernel 2.6 and a stricter design: one value per file, arranged by the kernel's model of devices and drivers. New device information goes to /sys; /proc keeps processes and its historical files.

How does atfq read your machine?

Mostly from these two trees: memory from /proc/meminfo, processes from /proc/PID/stat, disks from /sys/block, network interfaces from /sys/class/net. Reading files needs no root and runs no other program, which is why atfq can stay read-only.

Commands
cat sysctl
Paths
/proc /sys /proc/sys
See also
13.1 The hierarchy in 2 minutes