Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Exploring the proc File System in Linux

· 6 min read · Home Tech

In this article
  1. What Is the proc File System?
  2. Key Directories and Files in /proc
  3. How to Read Process Information
  4. Kernel Tunables in /proc/sys
  5. Common Uses and Tools
  6. Security and Safety Considerations
  7. Frequently Asked Questions

The proc file system (procfs) is a virtual filesystem in Linux that exposes kernel and process information as files and directories, allowing users and programs to interact with kernel data through standard file I/O. This article explains how procfs works, what you can find inside it, and how to use it safely for system monitoring and debugging.

What Is the proc File System?

Procfs is mounted at /proc by default on most Linux distributions. Unlike a regular filesystem stored on a disk, procfs is a virtual filesystem that exists only in memory. When you read a file in /proc, the kernel generates the content on the fly based on the current system state. Writing to certain files can trigger kernel actions, such as changing system parameters.

The name "proc" comes from "process," because the original purpose was to provide information about running processes. Over time, it expanded to include a wide range of kernel data, from CPU and memory statistics to network and hardware details.

Key Directories and Files in /proc

When you list the contents of /proc, you'll see a mix of numbered directories and named files. The numbered directories correspond to process IDs (PIDs) of currently running processes. For example, /proc/1 is the init process (systemd on most modern systems). Each process directory contains files describing the process's state, command line, environment, memory maps, and more.

Some important files and directories include:

  • /proc/cpuinfo – details about the CPU(s), such as model, cores, and flags.
  • /proc/meminfo – memory usage statistics, including total, free, and available memory.
  • /proc/loadavg – system load averages for 1, 5, and 15 minutes.
  • /proc/uptime – system uptime and idle time.
  • /proc/version – kernel version and build details.
  • /proc/filesystems – list of filesystems supported by the kernel.
  • /proc/mounts – currently mounted filesystems (symlink to /proc/self/mounts).
  • /proc/sys – a special directory for kernel tunables (see below).

How to Read Process Information

Each process directory contains a set of standard files. For example, to see the command line of a process with PID 1234, you can run cat /proc/1234/cmdline. The output is null-separated, so you might want to use tr '\0' ' ' to make it readable.

Other useful process files include:

  • status – human-readable process state, PID, PPID, memory usage, and more.
  • stat – a single line of raw statistics about the process.
  • fd – a directory containing symlinks to the file descriptors opened by the process.
  • environ – the environment variables of the process, null-separated.
  • maps – memory regions mapped into the process address space.
  • io – I/O statistics for the process.

You can also use tools like ps, top, and htop that read from /proc behind the scenes, but knowing how to read the raw files helps when those tools aren't available or when you need specific data.

Kernel Tunables in /proc/sys

The /proc/sys directory contains files that control kernel parameters. These are grouped by subsystem, such as net, vm, fs, and kernel. For example, /proc/sys/vm/swappiness controls how aggressively the kernel swaps memory. To view the current value, run cat /proc/sys/vm/swappiness. To change it temporarily, you can write to the file with echo 10 > /proc/sys/vm/swappiness (requires root).

Changes made this way are lost on reboot. To make them persistent, you can add entries to /etc/sysctl.conf or files in /etc/sysctl.d/. The sysctl command is a more user-friendly interface for the same functionality. For example, sysctl vm.swappiness displays the current value, and sysctl -w vm.swappiness=10 sets it.

Be careful when modifying kernel parameters. Some changes can degrade performance or even crash the system. Only adjust settings you understand, and test changes in a non-production environment first.

Common Uses and Tools

System administrators and developers use /proc for a variety of tasks:

  • Monitoring system health – checking CPU, memory, and load averages.
  • Debugging processes – examining file descriptors, memory maps, and environment.
  • Performance tuning – adjusting kernel parameters like swappiness, file-max, and network buffers.
  • Security auditing – inspecting open ports and network connections via /proc/net.
  • Container and sandboxing – tools like Docker rely on /proc to manage namespaces and cgroups.

Many command-line utilities parse /proc to provide human-readable output. For example, free reads /proc/meminfo, and ps reads process directories. If you write scripts, you can directly read /proc files to get raw data without needing external tools.

Security and Safety Considerations

Because /proc exposes kernel internals, there are security implications. Some files contain sensitive information, such as environment variables or memory maps of processes, which could reveal credentials or other data. To mitigate this, Linux uses a feature called "hidepid" that restricts access to process directories for non-root users. You can mount /proc with the hidepid=2 option to only show your own processes.

Writing to /proc/sys files can change system behavior, so it should only be done by administrators who understand the consequences. Also, never assume that a file in /proc is a regular file; always treat it as a virtual interface. For example, reading from /proc/kcore (the kernel's memory) can hang or crash the system if done incorrectly.

Another misconception is that /proc is a place to store data – it isn't. Writing to most files doesn't persist anything; it only sends a command to the kernel. If you need to store system information persistently, use a regular filesystem like ext4 or XFS.

Frequently Asked Questions

Is /proc a real filesystem?

No, /proc is a virtual filesystem. It doesn't occupy disk space, and its contents are generated dynamically by the kernel. When you read a file, the kernel computes the data in real time. This is why the sizes of files in /proc often appear as 0 – the size is not known until you read the content.

Why do some /proc files show 0 bytes?

Because they are virtual files, the kernel doesn't know the size in advance. When you read or write, the data is generated or consumed on the fly. The 0-byte size is just a placeholder; the actual content can be large.

Can I delete files in /proc?

No. Deleting a file in /proc is not allowed and would have no effect. The files are not stored on disk; they are interfaces to kernel data. Attempting to delete them will result in an error.

How do I see all processes using /proc?

You can list the directories in /proc that are numeric (PIDs) and then read the status file in each to get the process name and state. Tools like ps do this automatically. To see only your own processes, you can use ps -u $(whoami) or mount /proc with hidepid=2.

What is the difference between /proc and /sys?

/proc focuses on process and general system information, while /sys (sysfs) exposes device and driver information in a more structured way. /sys is also virtual but is organized by device tree rather than by process. Both are used for kernel interaction, but they serve different purposes.