The /proc Filesystem
/proc is one of Linux's most ingenious designs. It's a virtual filesystem — nothing in it is stored on disk. The kernel generates file contents on the fly when you read them. Every tool you use for monitoring (top, ps, free) reads from /proc.
Per-Process Information — /proc/PID/
Every running process has its own directory at /proc/PID/:
ls /proc/1/
# cmdline cwd environ exe fd/ maps mem net/
# ns/ oom_score smaps stat status task/
# The command that started the process
cat /proc/1/cmdline | tr '\0' ' '
# /sbin/init splash
# Current working directory
ls -la /proc/1/cwd # symlink to actual directory
# Open file descriptors
ls -la /proc/1/fd/
# 0 -> /dev/null (stdin)
# 1 -> /dev/null (stdout)
# 2 -> /dev/console (stderr)
# Memory map — all virtual memory regions
cat /proc/1/maps
# address perms offset dev inode pathname
# 7f8a12000000-7f8a16000000 r--p ... /lib/x86_64/libc.so.6
# Environment variables (NUL-separated)
cat /proc/1/environ | tr '\0' '\n'
# Namespaces this process belongs to
ls -la /proc/1/ns/
System-Wide Information
| File | What it shows |
|---|---|
| /proc/cpuinfo | CPU model, cores, flags, clock speed |
| /proc/meminfo | RAM: total, free, available, cached, swap |
| /proc/loadavg | 1/5/15 min load average + running/total processes |
| /proc/uptime | Seconds since boot, seconds idle |
| /proc/stat | CPU time breakdown, context switches, interrupts, boot time |
| /proc/diskstats | Per-disk I/O counters (reads, writes, time spent) |
| /proc/net/dev | Per-interface network stats |
| /proc/interrupts | Per-CPU interrupt counts by IRQ |
/proc/sys — Kernel Tuning
How do you tune kernel parameters?
By reading and writing files in
/proc/sys/. The sysctl command is just a friendly interface to these files.
# Read a kernel parameter
cat /proc/sys/net/ipv4/ip_forward # 0 or 1
# Change it (takes effect immediately, not persistent)
echo 1 > /proc/sys/net/ipv4/ip_forward
# Same thing with sysctl
sysctl net.ipv4.ip_forward # read
sysctl -w net.ipv4.ip_forward=1 # write
# Make persistent across reboots
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p # apply sysctl.conf
Key tunable areas: /proc/sys/vm/ (memory behavior), /proc/sys/net/ (networking), /proc/sys/kernel/ (scheduler, core dumps, panic behavior).