The proc file system contains a hierarchy of special files that represent the current state of the kernel. It is named after its original purpose, which is an interface to the structures within running processes to support debugging tools. Linux adopted this from Solaris but also added the interface to the kernel. The proc file system has become quite messy over the years so Linux created the sysfs file system to clean it up.

 

Files in the /proc directory contain information about your hardware and current processes running on your system. Files that have write permission can be modified to change the configuration of the kernel.

 

Virtual File System

 

Files in the /proc directory are virtual files; therefore, proc is referred to as a virtual file system. Most virtual files are listed as zero bytes in size but contain a large amount of information when viewed. Most of the time and date stamps on virtual files reflect the current time and date; however, these files are constantly updated.

 

Virtual files such as /proc/interrupts, /proc/meminfo, /proc/cpuinfo, and /proc/devices provide a view of the system’s hardware. Others, like the /proc/filesystems file and the /proc/sys directory provide system configuration information and interfaces. Files containing information about similar topics are grouped into virtual directories. For example, process directories contain information about each running process on the system.

 

Viewing Virtual Files

 

Most virtual files within /proc can be viewed by using commands such as cat, more, and less. For example, to view information about the system’s CPU, enter:

# cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 79
model name	: Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
stepping	: 1
microcode	: 0x1
cpu MHz		: 2199.998
cache size	: 30720 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt
bogomips	: 4399.99
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management:

Certain files can only be accessed with root privileges. Some files in /proc contain information that is not human readable. Use utilities such as lspci, free, and top to view these files. For example, use the lspci command to list all PCI devices:

# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Red Hat, Inc. QXL paravirtual graphic card (rev 04)
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
00:04.0 SCSI storage controller: Red Hat, Inc Virtio SCSI
00:05.0 SCSI storage controller: Red Hat, Inc Virtio block device
00:06.0 SCSI storage controller: Red Hat, Inc Virtio block device
00:07.0 Unclassified device [00ff]: Red Hat, Inc Virtio memory balloon

 

Changing Virtual Files

 

Most virtual files within the /proc directory are read-only. However, some are writable and can be used to adjust settings in the kernel. This is especially true for files in the /proc/sys directory. To change the value of a virtual file, use the following syntax:

# echo value > /proc/file

 

For example, to change the host name, enter:

# echo www.example.com > /proc/sys/kernel/hostname

 

Other files act as binary or Boolean switches. Viewing the file returns either a 0 (off or false) or a 1 (on or true). Example:

# cat /proc/sys/net/ipv4/ip_forward 
0

 

The 0 indicates the kernel is not forwarding network packets. To turn packet forwarding on:

# echo 1 > /proc/sys/net/ipv4/ip_forward
# cat /proc/sys/net/ipv4/ip_forward
1

 

Top-Level Files Within /proc

 Some of the more useful virtual files in the top-level of the /proc directory are described here. This is not meant to be an all-inclusive list, but to give examples of some of the files and their purpose. Many of these files are described further in applicable lessons.

 

  • /proc/buddyinfo: This file is used primarily for diagnosing memory fragmentation issues.
  • /proc/cmdline: This file shows the parameters passed to the kernel at the time it is started.
  • /proc/cpuinfo: This virtual file identifies the type of processor used by your system.
  • /proc/crypto: This file lists all installed cryptographic ciphers used by the Linux kernel, including additional details for each.
  • /proc/devices: This file displays the various character and block devices currently configured (not including devices whose modules are not loaded).
  • /proc/dma: This file contains a list of the registered ISA DMA channels in use.
  • /proc/execdomains: This file lists the execution domains currently supported by the Linux kernel, along with the range of personalities they support.
  • /proc/filesystems: This file displays a list of the file system types currently supported by the kernel. The first column signifies whether the file system is mounted on a block device. Those beginning with nodev are not mounted on a device. The second column lists the names of the file systems supported. The mount command cycles through the file systems listed here when one is not specified as an argument.
  • /proc/interrupts: This file records the number of interrupts per IRQ on the x86 architecture.
  • /proc/iomem: This file shows you the current map of the system’s memory for each physical device.
  • /proc/ioports: This file provides a list of currently registered port regions used for input or output communication with a device.
  • /proc/kcore: This file represents the physical memory of the system and is stored in the core file format. The contents of this file are designed to be examined by a debugger, such as gdb, and is not human readable.
  • /proc/kmsg: This file is used to hold messages generated by the kernel. These messages are then picked up by other programs, such as /bin/dmesg.
  • /proc/loadavg: This file provides a look at the load average in regard to both the CPU and I/O over time, as well as additional data used by uptime and other commands.
  • /proc/locks: This file displays the files currently locked by the kernel. The contents of this file contain internal kernel debugging data and can vary tremendously, depending on the use of the system.
  • /proc/mdstat: This file contains the current information for multiple-disk, RAID configurations.
  • /proc/meminfo: This file reports a large amount of valuable information about the system’s RAM usage.
  • /proc/modules: This file displays a list of all modules loaded into the kernel. Most of this information can also be viewed by using the /sbin/lsmod command.

 

Process Directories in /proc

 

The /proc directory contains directories with numerical names. These directories are named after a program’s process ID and contain information about that process. The owner and group of each process directory are set to the user running the process. Each process directory contains several files including:

 

  • cmdline: The command issued when starting the process
  • cwd: A symbolic link to the current working directory for the process
  • environ: A list of the environment variables for the process
  • exe: A symbolic link to the executable of this process
  • fd: The directory containing all of the file descriptors for a particular process
  • maps: A list of memory maps to executables and library files associated with process
  • mem: The memory held by the process (the file cannot be read by the user)
  • root: A link to the root directory of the process
  • stat: The status of the process including run state and memory usage
  • statm: The status of the memory in use by the process
  • status: The status of the process in a more readable form than stat or statm

 

Other Directories in /proc

 

Other directories within the/proc directory group similar information by topic. The following is a partial list of these directories:

 

  • /proc/bus: This directory contains information about the various buses available on the system. The subdirectories and files available within /proc/bus vary depending on the devices connected to the system.
  • /proc/bus/pci, /proc/bus/usb: You can get a list of all PCI and USB devices present on the system by using the cat command on the devices file within these directories, but the output is difficult to read and interpret. For a human-readable list of devices, run the lspci and lsusb commands.
  • /proc/driver: This directory contains information for specific drivers in use by the kernel.
  • /proc/fs: This directory shows which file systems are exported. If running an NFS server, typing cat /proc/fs/nfsd/exports displays the file systems being shared and the permissions.
  • /proc/irq: This directory is used to set IRQ to CPU affinity, which allows the system to connect a particular IRQ to only one CPU. Alternatively, it can exclude a CPU from handling any IRQs.
  • /proc/self/net: This directory provides a comprehensive look at various networking parameters and statistics. Each directory and virtual file within this directory describes aspects of the system’s network configuration. The /proc/net file is a symbolic link to this directory.
  • /proc/scsi: 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 device, as well as the model name, vendor, SCSI channel, and ID data is available.
  • /proc/sys: This directory is different from others in /proc, because it not only provides information about the system but also allows you to immediately enable and disable kernel features. If a file has write permissions, it can be used to configure the kernel. Changing a value within a /proc/sys/ file is done by echoing the new value into the file.

 

For example, to change the host name to www.example.com:

# echo www.example.com > /proc/sys/kernel/hostname

 

Other files act as binary or Boolean switches. A value of 0 represents off or false. A value of 1 represents on or true. For example, to turn packet forwarding on:

# echo 1 > /proc/sys/net/ipv4/ip_forward

 

Changes made by using the echo command are not persistent and disappear when the system is restarted. To make configuration changes take effect after the system is rebooted, add them to the /etc/sysctl.conf file.

 

  • /proc/sys/dev: This directory provides parameters for particular devices on the system.
  • /proc/sys/fs: This directory contains options and information concerning various aspects of the file system, including quota, file handle, and inode information.
  • /proc/sys/kernel: This directory contains a variety of different configuration files that directly affect the operation of the kernel.
  • /proc/sys/net: This directory contains subdirectories concerning various networking topics. You can alter the files within these directories to adjust the network configuration on a running system.
  • /proc/sysvipc: This directory contains information about System V Interprocess Communication (IPC) resources. The files in this directory relate to System V IPC calls for messages (msg), semaphores (sem), and shared memory (shm).
  • /proc/tty: This directory contains information about the available and currently used tty devices on the system. The drivers file is a list of the current tty devices in use.
Was this answer helpful? 0 Users Found This Useful (0 Votes)