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 that represent the current state of the kernel — allowing applications and users to peer into the kernel's view of the system.
Within the /proc/ directory, one can find a wealth of information about the system hardware and any processes currently running. In addition, some of the files within the /proc/ directory tree can be manipulated by users and applications to communicate configuration changes to the kernel.
In 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 subdirectories. For instance, /proc/ide/ contains information for all physical IDE devices. Likewise, process directories contain information about each running process on the system.
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 output 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.
Some of the virtual files in the /proc/ directory are only readable by the root user.
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 name.example.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.
Common groups of information concerning the kernel are grouped into directories and subdirectories within the /proc/ directory.
Every /proc/ directory contains a number of directories numerical names. A listing of them may start off like this:
dr-xr-xr-x 3 root root 0 Feb 13 01:28 1 dr-xr-xr-x 3 root root 0 Feb 13 01:28 1010 dr-xr-xr-x 3 xfs xfs 0 Feb 13 01:28 1087 dr-xr-xr-x 3 daemon daemon 0 Feb 13 01:28 1123 dr-xr-xr-x 3 root root 0 Feb 13 01:28 11307 dr-xr-xr-x 3 apache apache 0 Feb 13 01:28 13660 dr-xr-xr-x 3 rpc rpc 0 Feb 13 01:28 637 dr-xr-xr-x 3 rpcuser rpcuser 0 Feb 13 01:28 666
These directories are called process directories because they are named after a program's process ID and contain information specific to that process. The owner and group of each process directory is set to the user running the process. When the process is terminated, its /proc/ process directory vanishes.
Other than the process's name and ID, the state (such as S (sleeping) or R (running) and user/group ID running the process is available, as well as much more detailed data regarding memory usage.
The /proc/self/ directory is a link to the currently running process. This allows a process to look at itself without having to know its process ID. Within a shell environment, a listing of the /proc/self/ directory produces the same contents as listing the process directory for that process.
This directory contains information specific to the various buses available on the system. So, for example, on a standard system containing ISA, PCI, and USB busses, current data on each of these buses is available in its directory under /proc/bus/.
The contents of the subdirectories and files available vary greatly on the precise configuration of your system. However, each of the directories for each of the bus types has at least one directory for each bus of that type. These individual bus directories, usually signified with numbers such as 00, contain binary files that refer to the various devices available on that bus.
For example, a system with a USB bus but no USB devices connected to it has a /proc/bus/usb/ directory containing several files.
The /proc/bus/usb/ directory contains files that track the various devices on any USB busses, as well as the drivers required to use them. The /proc/bus/usb/001/ directory contains all devices on the first USB bus. By looking at the contents of the devices file, you can identify the USB root hub on the motherboard.
This directory contains information for specific drivers in use by the kernel. A common file found here is rtc, which provides output from the driver for the system's Real Time Clock (RTC), the device that keeps the time while the system is switched off. For more information about the RTC, review /usr/src/linux-2.4/Documentation/rtc.txt.
This directory shows which file systems are exported. If you are running an NFS server, you can type cat /proc/fs/nfs/exports to view the file systems being shared and the permissions granted for those file systems.
This directory holds information about IDE devices on the system. Each IDE channel is represented as a separate directory, such as /proc/ide/ide0 and /proc/ide/ide1. In addition, a drivers file is also available, providing the version number of the various drivers used on the IDE channels:
ide-cdrom version 4.59 ide-floppy version 0.97 ide-disk version 1.10
Many chipsets also provide an informational file in this directory that gives additional data concerning the drives connected through the channels. For example, a generic Intel PIIX4 Ultra 33 chipset produces a /proc/ide/piix that tells you whether DMA or UDMA is enabled for the devices on the IDE channels.
Within each IDE channel directory is a device directory. The name of the device directory corresponds to the drive letter in the /dev/ directory. For instance, the first IDE drive on ide0 would be hda.
There is a symlink to each of these device directories in the /proc/ide/ directory.
Each device directory contains a collection of information and statistics. The contents of these directories vary according to the type of device connected. Some of the more useful files common to many devices include:
cache — The device's cache.
capacity — The capacity of the device, in 512 byte blocks.
driver — The driver and version used to control the device.
geometry — The physical and logical geometry of the device.
media — The type of device, such as a disk.
model — The model name or number of the device.
settings — A collection of current parameters of the device. This file usually contains useful technical information.
This directory is used to set IRQ-to-CPU affinity, which allows you to connect a particular IRQ to only one CPU. Alternatively, you can exclude a CPU from handling any IRQs. Each IRQ has its own directory, allowing for individual configuration of each IRQ. The /proc/irq/prof_cpu_mask file is a bitmask that contains the default values for the smp_affinity file in the IRQ directory. The values in smp_affinity specify which CPUs handle that particular IRQ. /usr/src/linux-2.4/Documentation/filesystems/proc.txt contains more information.
This directory provides a comprehensive look at various networking parameters and statistics. Each of the files covers a specific range of information related to networking on the system.
This directory is analogous to the /proc/ide/ directory only it is for connected SCSI devices. The primary file in this directory is /proc/scsi/scsi, which contains a list of every recognized SCSI device. From this listing, the type of devices, as well as the model name, vendor, SCSI channel, and ID data is available.
Each SCSI driver used by the system has its own directory in /proc/scsi/, which contains files specific to each SCSI controller using that driver. So, for the Adaptec AIC-7880 Ultra SCSI host adapter, for example, the aic7xxx and megaraid directories are present because those two drivers are being utilized. The files in each of the directories typically contain I/O address range, IRQ, and statistics for the particular SCSI controller using that driver. Each controller can report a different type and amount of information.
The /proc/sys/ directory is different from others in /proc/ because it not only provides information about the system but also allows you to make configuration changes to the kernel. This allows the administrator of the machine to immediately enable and disable kernel features. The /proc/sys/ directory contains several subdirectories that control different aspects of a running kernel.
Use caution when changing settings on a production system using the various files in the /proc/sys/ directory. Changing the wrong setting may render the kernel unstable, requiring a reboot of the system. For this reason, be sure you know the valid options for that file and the expected outcome before attempting to change a value in /proc/sys/.
This directory provides parameters for particular devices on the system. Most systems have at least two directories, cdrom and raid, but customized kernels can have others, such as parport, which provides the ability to share one parallel port between multiple device drivers.
The cdrom directory contains a file called info that reveals a number of important CD-ROM parameters. Various files in /proc/sys/dev/cdrom, such as autoclose and checkmedia, can be used to control the system's CD-ROM. Use the echo command to enable or disable to disable these features.
If RAID support is compiled into the kernel, a /proc/sys/dev/raid/ directory will be available with at least two files in it: speed_limit_min and speed_limit_max. These settings determine how much to accelerate the RAID device for particularly I/O-intensive tasks, such as resyncing the disks.
This directory contains an array of options and information concerning various aspects of the file system, including quota, file handle, inode, and dentry information. The binfmt_misc directory is used to provide kernel support for miscellaneous binary formats.
This directory contains a variety of different configuration files that directly affect the operation of the kernel.
This directory contains assorted directories concerning various networking topics. Various configurations at the time of kernel compilation make different directories available here, such as appletalk, ethernet, ipv4, ipx, and ipv6. Within these directories you can adjust the assorted networking values for that configuration on a running system. Additional information about these directories and the possible values for their configuration files can be found in /usr/src/linux-2.4/Documentation/filesystems/proc.txt.
An erroneous change to these files may affect your remote connectivity to the system.
This directory facilitates the configuration of the Linux kernel's virtual memory (VM) subsystem. The kernel makes extensive and intelligent use of virtual memory, which is commonly called swap space. The /usr/src/linux-2.4/Documentation/sysctl/vm.txt file contains additional information on these various files.
This directory contains information about System V IPC resources. The files in this directory relate to System V IPC calls for messages (msg), semaphores (sem), and shared memory (shm).
This directory contains information about the available and currently used tty devices on the system. Originally called a teletype device, any character-based data terminals are called tty devices. In Linux, there are three different kinds of tty devices:
Serial devices — These tty devices are used with serial connections, such as over a modem or using a serial cable.
Virtual terminals — These tty devices create the common console connection, such as the virtual consoles available by pressing Alt-Function key at the system console.
Pseudo terminals — These tty devices create a two-way communication that is used by some higher level applications such as X11. The drivers file is a list of the current tty devices in use.
Most of the best /proc/ documentation is available on your system:
/usr/src/linux-2.4/Documentation/filesystems/proc.txt — Contains assorted but limited information about all aspects of the /proc/ directory.
/usr/src/linux-2.4/Documentation/sysrq.txt — An overview of System Request Key options.
/usr/src/linux-2.4/Documentation/sysctl — A directory containing a variety of sysctl tips, including modifying values that concern the kernel (kernel.txt), accessing file systems (fs.txt), and virtual memory use (vm.txt).
/usr/src/linux-2.4/Documentation/networking/ip-sysctl.txt — A look at various IP networking options.
/usr/src/linux-2.4 — Some of the most authoritative information on /proc/ can be found by reading the kernel source code. Make sure the kernel-source RPM is installed on your system and look in the /usr/src/linux-2.4 directory for the source code.
http://www.linuxhq.com — This site maintains a complete database of source, patches, and documentation for various versions of the Linux kernel.