Problem Statement
Explain the /proc filesystem in Linux. What information does it provide and how do you use it for process and system monitoring?
Explanation
The /proc filesystem is a virtual filesystem providing an interface to kernel data structures, appearing as files and directories but existing only in memory. Each running process has a directory /proc/PID containing detailed process information. /proc also contains system-wide information files for hardware, memory, CPU, and kernel parameters.
Process-specific files in /proc/PID include: cmdline (command with arguments), environ (environment variables), exe (symlink to executable), cwd (current working directory), fd/ (open file descriptors), status (detailed status including memory usage, UIDs, GIDs), limits (resource limits), and maps (memory mappings). Example: cat /proc/1234/cmdline shows the command for PID 1234.
System-wide files include: /proc/cpuinfo (CPU details), /proc/meminfo (memory details more complete than free), /proc/version (kernel version), /proc/uptime (system uptime), /proc/loadavg (load average), /proc/mounts (mounted filesystems), /proc/net/ (network statistics), and /proc/sys/ (tunable kernel parameters).
Practical usage: cat /proc/meminfo | grep MemAvailable checks available memory, cat /proc/cpuinfo | grep processor | wc -l counts CPU cores, cat /proc/PID/status | grep VmRSS shows process memory usage. Write to /proc/sys to tune kernel parameters: echo 1 > /proc/sys/net/ipv4/ip_forward enables IP forwarding. Understanding /proc enables low-level system inspection and tuning without external tools.
Practice Sets
This question appears in the following practice sets:
