patternbashModerate
/proc and /sys: Reading Kernel State at Runtime
Viewed 0 times
/proc/syssysctlkernel parametersvm.swappinesscpufreqprocess infovirtual filesystem
linux
Error Messages
Problem
Need to inspect or tune kernel parameters at runtime without rebooting, or diagnose hardware and process state without specialized tools.
Solution
Read from /proc for process and kernel info; read/write /sys for hardware and driver parameters.
# CPU info
cat /proc/cpuinfo
# Memory info
cat /proc/meminfo
# Loaded kernel modules
cat /proc/modules
lsmod
# Running process info (PID 1234)
ls /proc/1234/
cat /proc/1234/cmdline | tr '\0' ' '
cat /proc/1234/status
ls -la /proc/1234/fd/ # open file descriptors
# Kernel parameters (sysctl)
sysctl vm.swappiness
sysctl -a | grep net.ipv4
# Change kernel parameter at runtime
sysctl -w vm.swappiness=10
# Persist across reboots
echo 'vm.swappiness=10' >> /etc/sysctl.conf
sysctl -p
# /sys: hardware tuning (e.g., CPU governor)
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governorWhy
/proc is a virtual filesystem — files have no disk size but reading them queries the kernel. /sys exposes the device model and driver attributes. sysctl is the canonical interface for kernel tunable parameters.
Gotchas
- Writing to /sys survives only until the next reboot — use udev rules or systemd for persistence.
- sysctl -p reads /etc/sysctl.conf by default; drop-in files in /etc/sysctl.d/ require
sysctl --system. - Not all /proc files are world-readable — some require root (e.g., /proc/1/maps for another user's process).
- Modifying /proc/sys/net values can immediately affect running network connections.
Revisions (0)
No revisions yet.