Chapter 4. The /proc Filesystem

The /proc directory contains virtual files that are windows into the current state of the running Linux kernel. This allows the user to peer into a vast array of information, effectively providing them with the kernel's point-of-view within the system. In addition, the user can use the /proc directory to communicate particular configuration changes to the kernel.

A Virtual Filesystem

In Linux, everything is stored in files. 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 filesystem associated with your hard disks, CD-ROM, or any other physical storage device connected to your system (except, arguably, your RAM). Rather, these files are part of a virtual filesystem, enabled or disabled in the Linux kernel when it is compiled.

By default, when a Red Hat Linux system starts up, a line in /etc/fstab is responsible for mounting the /proc filesystem.

none         /proc       proc       defaults       0 0

The status of whether or not /proc is currently mounted can be determined by typing the mount command with no arguments. This will display all of your current mounts, and a line similar to this should appear in the list if /proc is mounted:

none on /proc type proc (rw)

If you would like to mount /proc manually, type this command:

mount -t proc proc /proc

The /proc virtual filesystem is a switch in the configuration of the Linux kernel, one that is turned on by default. If, for whatever reason, you would like to completely disable /proc on your system, de-select /proc file system support within the File system configuration section of config, menuconfig, or xconfig when rebuilding your kernel. Alternatively, you can simply comment out the /proc line in /etc/fstab to prevent it from being mounted.

The best way to understand /proc as a virtual filesystem is to list the files in the directory. The following is only a partial excerpt of such a list:

[root@bleach /]# ls -l /proc
-r--r--r--    1 root     root            0 May  3 11:42 cmdline
-r--r--r--    1 root     root            0 May  3 11:42 cpuinfo
-r--r--r--    1 root     root            0 May  3 11:42 devices
-r--r--r--    1 root     root            0 May  3 11:42 dma
dr-xr-xr-x    2 root     root            0 May  3 11:42 driver
-r--r--r--    1 root     root            0 May  3 11:42 execdomains
-r--r--r--    1 root     root            0 May  3 11:42 fb
-r--r--r--    1 root     root            0 May  3 11:42 filesystems
[root@bleach /]#

The /proc virtual files exhibit some interesting qualities. First, most of them are 0 bytes in size. However, when the file is viewed, it likely contains 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.

Various programs use the /proc filesystem to discover the parameters of a system so that they can provide better performance and deliver more features.

In addition, a system administrator can use /proc as an easy method of accessing information about the state of the kernel, the attributes of the machine, the states of individual processes, and more. Most of the files in this directory, such as interrupts, meminfo, mounts, and partitions, provide an up-to-the-moment glimpse of a system's environment. To make things easier, files that contain information covering a similar topic are grouped into virtual directories and sub-directories, such as /proc/ide.

Viewing Virtual Files

By using cat, more, or less commands in combination with the files within /proc, you can immediately access an enormous amount of information about the system. As an example, if you want to see how the memory registers are currently assigned on your computer:

[root@bleach /]# cat /proc/iomem
00000000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000a0000-000bffff : Video RAM area
000c0000-000c7fff : Video ROM
000f0000-000fffff : System ROM
00100000-03ffcfff : System RAM
  00100000-002557df : Kernel code
  002557e0-0026c80b : Kernel data
03ffd000-03ffefff : ACPI Tables
03fff000-03ffffff : ACPI Non-volatile Storage
dc000000-dfffffff : S3 Inc. ViRGE/DX or /GX
e3000000-e30000ff : Lite-On Communications Inc LNE100TX
  e3000000-e30000ff : eth0
e4000000-e7ffffff : Intel Corporation 440BX/ZX - 82443BX/ZX Host bridge
ffff0000-ffffffff : reserved
[root@bleach /]# 

Or (and more usefully), if were connecting to an unknown machine and wanted to know its CPU type and speed, you can use the following command:

[root@bleach /]# cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 6
model name	: Celeron (Mendocino)
stepping	: 0
cpu MHz		: 416.537
cache size	: 128 KB
fdiv_bug	: no
hlt_bug		: no
f00f_bug	: no
coma_bug	: no
fpu		: yes
fpu_exception	: yes
cpuid level	: 2
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov
bogomips	: 830.66
[root@bleach ide]# 

As you can see, some of the information makes sense immediately, while other areas seem to be in a strange code. Some of the /proc files will be senseless without a legend to guide you. In many cases, utilities exist on the system, such as free and top, that pull data from these files and display it in a useful way.

Another interesting quality of virtual files can be seen when viewing them with the more command, which usually tells gives your location in the file by displaying the percentage of the document you are currently seeing. This percentage number usually climbs the further you navigate down a long file. However, when viewing a /proc virtual file, the percentage amount never changes, always staying at 0%.

A few of the files in /proc are set to only be readable by root, so you may need to become the root user before attempting to read them.

WarningWarning
 

Be sure to avoid viewing the kcore file in /proc. This virtual file contains an image of the kernel's memory, and the contents of the file will do strange things to your terminal. You may need to type reset after hitting [Ctrl]-[C] to get back to a proper command line prompt.