The /proc filesystem

April 26, 2005
Linux has become really popular as a server operating system mainly due to its security and stability. Infact the system administrators could do system maintanence tasks short of any hardware upgradations without rebooting the machine. That means there is virtually no downtime suffered by a linux server. This is made possible because Linux provides various ways to change the underlying operating system values and settings while keeping the system up and running. Linux contains a virtual filesystem called /proc which can be accessed by the system administrators to achieve the above tasks.
A /proc filesystem is not a real filesystem because it resides only in the computer's memory and does not utilize any space on the hard disk. This filesystem is a map to the running kernel process. The /proc filesystem is mounted in the /proc directory during system initialization and has an entry in the /etc/fstab file.
If you move into the /proc directory, you will find a lot of sub directories and files. Some of these files give information on system hardware, networking settings and activity, memory usage and so on of your computer. And there are some other files in the /proc/sys directory whose values you can manipulate to make changes to the various parameters of the running kernel settings.
Here I will describe the various files and directories residing in /proc that a system administrator could find helpful.
If you list the files under /proc, you will find that all the files have a size of zero - this is because they are not really files and directories in the typical sense. If you want to view the contents of a file in the /proc directory, you use the 'cat' command.
WARNING: Do not use 'cat' on /proc/kcore as this is a special file which is an image of the running kernel's memory at that particular moment - cat'ing this file will leave your terminal unusable.
Some of the key files in the top-level directory are as follows :
  • /proc/interrupts - View IRQ settings
  • /proc/cpuinfo - Information about the system's CPU(s)
  • /proc/dma - Direct Memory Access (DMA) settings
  • /proc/ioports - I/O settings.
  • /proc/meminfo - Information on available memory, free memory, swap, cache memory and buffers. You can also get the same information using the utilities free and vmstat.
  • /proc/loadavg - System load average
  • /proc/uptime - system uptime and idle time. Can also be obtained using utility uptime.
  • /proc/version - Linux kernel version, build host, build date etc. Can also be obtained by executing `uname -a`.
Beneath the top-level /proc directory are a number of important subdirectories containing files with useful information. These include :
  • /proc/scsi - Gives information about SCSI devices
  • /proc/ide - information about IDE devices
  • /proc/net - information about network activity and configuration
  • /proc/sys - Kernel configuration parameters. The values in files in this directory are editable by root, which I will further explain below.
  • /proc/ - information about process PID.
/proc/sys directory
As explained earlier, this directory holds most kernel configuration parameters and is the one that is designed to be changed while the system is running. Some of the files which are of real use to the system administrators are as follows:
  • /proc/sys/fs/file-max
    This specifies the maximum number of file handles that can be allocated. If some of your users get an error when trying to open more files stating that the maximum limit of number of open files have been reached, then you need increase the value in this file (default is 4096) to set the problem straight as follows :
    # echo "10000" > /proc/sys/fs/file-max
  • /proc/sys/fs/super-max
    This specifies the maximum number of super block handlers. Any filesystem you mount needs to use a super block, so you could possibly run out if you mount a lot of filesystems.
    Default setting: 256
  • /proc/sys/kernel/acct
    This holds three configurable values that control when process accounting takes place based on the amount of free space (as a percentage) on the filesystem that contains the log:
    1. If free space goes below this percentage value then process accounting stops.
    2. If free space goes above this percentage value then process accounting starts.
    3. The frequency (in seconds) at which the other two values will be checked.
    To change a value in this file you should echo a space separated list of numbers.
    Default setting: 2 4 30
    These values will stop accounting if there is less than 2 percent free space on the filesystem that contains the log and starts it again if there is 4 or more percent free space. Checks are made every 30 seconds.
  • /proc/sys/kernel/ctrl-alt-del
    This file holds a binary value that controls how the system reacts when it receives the ctrl+alt+delete key combination. The two values represent:
    1. A zero (0) value means the ctrl+alt+delete is trapped and sent to the init program. This will allow the system to have a graceful shutdown and restart, as if you typed the shutdown command.
    2. A one (1) value means the ctrl+alt+delete is not trapped and no clean shutdown will be performed, as if you just turned the power off.
    Default setting: 0
  • /proc/sys/kernel/domainname
    This allows you to configure your network domain name. This has no default value and may or may not already be set.
  • /proc/sys/kernel/hostname
    This allows you to configure your network host name. This has no default value and may or may not already be set.
  • /proc/sys/net/ipv4/ip_forward
    This allows you to turn on/off IP forwarding. If the value in this file is "1" then ip forwarding is turned "on "and if value is "0" then ip forwarding is turned off.
This is only a small subset of 100's of configuration parameters that can be changed via the files in /proc/sys directory.
But the /proc/sys modifications are temporary and are not saved at system shutdown (which may be a rare instance as far as servers are concerned). But you can use the "sysctl" command to manage such settings in a static and centralized fashion. It reads the values in the /etc/sysctl.conf file. The sysctl command is called during boot time by the /etc/rc.d/rc.sysinit script. So to make the changes you make in the kernel parameters permanent, just enter it in the /etc/sysctl.conf file and then execute the command :
# sysctl -p
... to make the kernel reread the changes from the /etc/sysctl.conf file.
There are two simple rules for converting between files in /proc/sys and variables in sysctl:
  • Drop the /proc/sys from the beginning.
  • Swap slashes for dots in the filenames.
These two rules will let you swap any file name in /proc/sys for any variable name in sysctl.
So /proc/sys/net/ipv4/ip_forward will become net.ipv4.ip_forward
There is an interesting article about the /proc filesystem at Linux Gazette.

2 comments:

  • I must say, this is by far one of the better in-depth Linux sites I have found. Thanks for the wonderuful read.

    Have a GREAT day
    -Wes

  • There this tool that facilitates writing/reading /proc/sys variables:

    http://freshmeat.net/projects/lkcp