The Linux kernel has two primary functions: to control access to physical
devices on the computer and to schedule when and how processes interact
with these devices. The /proc/ directory contains a
hierarchy of special files which represent the current state of the
kernel — allowing applications and users to peer into the kernel's view of
the system.
A Virtual File System
Under Linux, all data are stored as files. Most users are familiar with
the two primary types of files: text and binary. But the
/proc/ directory contains another type of file
called a virtual file. It is for this reason that
/proc/ is often referred to as a virtual
file system.
These virtual files have unique qualities. Most of them are listed as
zero bytes in size and yet when one is viewed, it can contain a
large amount of information. In addition, most of the time and date
settings on virtual files reflect the current time and date, indicative
of the fact they constantly changing.
Virtual files such as interrupts,
/proc/meminfo, /proc/mounts, and
/proc/partitions provide an up-to-the-moment glimpse of
the system's hardware. Others, like /proc/filesystems
and the /proc/sys/ directory provide system
configuration information and interfaces.
For organizational purposes, files containing information on a similar
topic are grouped into virtual directories and sub-directories. For
instance, /proc/ide/ contains information for all
physical IDE devices. Likewise, process directories contain information
about each running process on the system.
Viewing Virtual Files
By using the cat, more, or
less commands on files within the
/proc/ directory, 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
/proc/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 |
When viewing different virtual files in the
/proc/ file system, you will notice some of the
information is easily understandable while some is not
human-readable. This is in part why utilities exist to pull data from
virtual files and display it in a useful way. Some examples of such
applications are lspci, apm,
free, and top.
 | Note |
|---|
| | Some of the virtual files in the /proc/
directory 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 bob.subgenius.com > /proc/sys/kernel/hostname |
Other files act as binary or boolean switches. For instance, if you
type cat /proc/sys/net/ipv4/ip_forward, you will
see 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.
 | Tip |
|---|
| | Another command used to alter settings in the
/proc/sys/ subdirectory is
/sbin/sysctl. For more information on this command,
see the Section called Using sysctl
|
For a listing of some of the kernel configuration files available in
the /proc/sys/, see the Section called /proc/sys/.