Chapter 2. The /proc File System

The Linux kernel's primary functions are to control access to physical devices on the computer and to schedule when and how processes interact with these devices. The /proc directory contains hierarchy of virtual folders and files which represent the current state of the kernel. Viewing files within /proc allows the user to peer into the kernel's view of the system. In addition, the user can use these virtual files to communicate configuration changes to the kernel.

A Virtual File System

In Linux, everything is stored as a file. Most users are familiar with the two primary types of files, text and binary. However, the /proc directory contains files that are not part of any file system associated with any physical storage device connected to your system. Instead, the virtual files in /proc are part of a virtual file system.

The virtual files in /proc have unique qualities. Most of them are 0 bytes in size. Yet when the file is viewed, it can contain quite a bit of information. In addition, most of their time and date settings reflect the current time and date, meaning that they are constantly changing.

Both applications and system administrators can use /proc as a method of accessing information about the state of the kernel, the attributes of the machine, the state of individual processes, and so on. Most of the files in the directory, such as interrupts, meminfo, mounts, and partitions, provide an up-to-the-moment glimpse of a system's physical environment. Others, like file systems and the /proc/sys/ directory provide software configuration information.

To make things easier, files that contain information covering a similar topic are grouped into virtual directories and sub-directories, such as /proc/ide/ for all physical IDE devices.

Viewing Virtual Files

By using cat, more, or less commands on the files within /proc, you can immediately access an enormous amount of information about the system. For example, if you want to see what sort of CPU your computer has, type cat cpuinfo and you will see something similar to the following:

processor	: 0
vendor_id	: AuthenticAMD
cpu family	: 5
model		: 9
model name	: AMD-K6(tm) 3D+ Processor
stepping	: 1
cpu MHz		: 400.919
cache size	: 256 KB
fdiv_bug	: no
hlt_bug		: no
f00f_bug	: no
coma_bug	: no
fpu		: yes
fpu_exception	: yes
cpuid level	: 1
wp		: yes
flags		: fpu vme de pse tsc msr mce cx8 pge mmx syscall 3dnow k6_mtrr
bogomips	: 799.53

As you view different virtual files in /proc, you will notice that some of the information makes sense. Others are not human readable. This is why utilities exist pull data from virtual files in /proc and display it in a useful way. Some examples of such applications are apm, free, and top.


Some of the virtual files in /proc are only readable by the root user.

Changing Virtual Files

As a general rule, most virtual files within the /proc directory are read only. However, some can be used to adjust settings in the kernel. This is especially true for files in the /proc/sys/ subdirectory.

To change the value of a virtual file, use the echo command and a > symbol to redirect the new value to the file. For instance, to change your hostname on the fly, you can type:

echo > /proc/sys/kernel/hostname 

Other files act as binary switches. For instance, if you type cat /proc/sys/net/ipv4/ip_forward, you will get either a 0 or a 1. A 0 indicates the kernel is not forwarding network packets. By using the echo command to change the value of the ip_forward file to 1, you can immediately turn packet forwarding on.

For a listing of some of the kernel configuration files available in the /proc/sys/, see the Section called /proc/sys/.