/proc
processes and kernel state, as files/proc is a view of the running system, not a place on a disk. The kernel creates its contents at the moment you read them. Every running process appears as a directory named by its number, and tools such as ps and top work by reading those files.
Nothing here is stored. It is the kernel, answering.
Why it exists
Every directory at the top of the tree is there for a reason. This is the problem /proc solves.
Rather than a special tool for each question, the kernel answers through files. Anything that can read a file can ask how much memory is free.
Each process gets /proc/ followed by its process id. Inside are its command line, its open files, its memory map and its environment.
Files under /proc/sys are kernel settings. Writing to one changes the running kernel immediately — it is how IP forwarding is switched on.
What you find inside
Not everything, but the entries worth recognising. Each is marked as a directory, a file, a link or a device.
- cpuinfofileThe processor: model, cores, features.
- meminfofileMemory in use and free.
- 1directoryThe first process started — systemd, on most systems.
- selflinkA link to the directory of whichever process is reading it.
- netdirectoryNetwork state, including the ARP table and interface counters.
- sysdirectoryKernel settings that can be read and changed.
At the terminal
Four commands that show what this directory is doing on a real machine.
cat /proc/cpuinfoShow the processor’s details.
cat /proc/meminfo | head -3Show total, free and available memory.
cat /proc/sys/net/ipv4/ip_forwardCheck whether this host forwards packets: 1 is yes, 0 is no.
ls -l /proc/$$/fdList the files your own shell has open. $$ is the shell’s process id.
Handle with care
What goes wrong here, and what someone securing or attacking the machine looks at.
A value written under /proc/sys lasts only until the machine restarts. To keep it, put it in /etc/sysctl.conf or a file in /etc/sysctl.d.
A process’s command line is readable by every user, so a password given as an argument is visible to all. Its environment is readable by its owner and root.