I created this brief post mainly to remind myself about the differences between /proc and /sys in Linux. I tend to forget the concepts very easy. I’m hoping this Linux information can also help somebody out there. First, I decided to take a walk in my hood in Brooklyn. Watch the dogs play at the park and come back to work.

In Linux, both the /proc and /sys directories are virtual filesystems that provide information about the system and allow interaction with the kernel. However, they serve different purposes and have distinct characteristics.

/proc (Process Information Filesystem)

Purpose: Provides information about running processes and system-wide kernel information.

Type: Virtual filesystem (procfs).

Usage: Primarily used for monitoring and debugging. Content:

  • Per-process directories (/proc/PID/): Contains details about each running process (e.g., /proc/1234/ for process ID 1234).
  • Kernel information files (/proc/cpuinfo, /proc/meminfo, /proc/uptime): Show real-time system statistics.
  • Configuration files (/proc/sys/): Some tunable kernel parameters can be modified here (though /sys is now preferred for hardware settings).
  • Virtual devices (/proc/mounts, /proc/partitions): Provides information about mounted filesystems and disk partitions.

Example Usage of /proc

View CPU details:

cat /proc/cpuinfo

Check system uptime:

cat /proc/uptime

List open file descriptors for a process (PID 1234):

ls -l /proc/1234/fd/

/sys (Kernel and Hardware Configuration Filesystem)

Purpose: Exposes kernel and hardware information, allowing users to configure certain kernel parameters dynamically.

Type: Virtual filesystem (sysfs).

Usage: Mainly used for interacting with hardware devices and kernel subsystems.

Content:

  • Device information (/sys/devices/): Shows a hierarchical view of connected devices.
  • Driver settings (/sys/bus/, /sys/class/): Allows interaction with kernel drivers and hardware components.
  • Kernel settings (/sys/kernel/): Provides access to kernel-specific configurations.
  • Power management (/sys/power/): Used for configuring system power states.

Example Usage of /sys

Check all block devices:

ls /sys/block/

Get detailed information about the first CPU core:

cat /sys/devices/system/cpu/cpu0/topology/core_id

Disable USB autosuspend for power saving:

echo 0 | sudo tee /sys/bus/usb/devices/usb1/power/autosuspend

Key Differences Between /proc and /sys

Feature/proc (procfs)/sys (sysfs)
PurposeProcess and system runtime informationKernel and hardware interaction
TypeVirtual filesystem (procfs)Virtual filesystem (sysfs)
ContentProcess details, kernel parameters, system statsHardware devices, kernel subsystems, driver configurations
Read/WriteMostly read-only (except /proc/sys/)Allows modifying hardware and kernel settings
Example File/proc/cpuinfo (CPU details)/sys/class/net/eth0/address (MAC address of eth0)
Main UseMonitoring and debugging system stateConfiguring kernel and hardware parameters

Use /proc to monitor system and process-related information.

Use /sys to interact with hardware and configure kernel settings.

Differences between /proc and /sys are a good step forward to learn more about the file system in Linux. I’m refreshing my head in order to renew one of my LPI certifications. Contact me if you have any questions.

Leave a comment

Your email address will not be published. Required fields are marked *