Proc

From LQWiki
Jump to navigation Jump to search

/proc

The Linux operating system provides a pseudo-file system that provides an interface to kernel information, and to receive information from a user or process. Any modifications made are lost on shutdown or reboot. /etc/sysctl.conf stores system parameters (/proc/sys/) to load at boot time, for values you want to preserve.


Example:

kolossus:~ # cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 3
model name      : Intel(R) Pentium(R) 4 CPU 3.00GHz
stepping        : 3
cpu MHz         : 2992.966
cache size      : 1024 KB
...

The /proc file system started out as a way to find information about processes, but now it is used by just about everything for which implementing a system call would be a waste.

The file system is not itself on a disk, rather, it is in kernel memory, where the kernel and its modules control what is inside these files. When a file in /proc is read, a function or handler is looked up (from a table within the kernel), and that function will output information. Likewise, when a file is written to in /proc, a bit of the kernel will handle reading it in.

Some examples of /proc usage are /proc/cmdline, /proc/cpuinfo, and /proc/config.gz. These provide two pieces of information about the kernel, the "command line" (the parameters passed to the kernel at boot), and the configuration file. Of course there is also loadavg, partitions, swaps, version, uptime, and so on.

Also of interest is /proc/apm and /proc/acpi, for thier respective power management systems. Each one reports information about the state of power management, to be gathered by various programs/monitors. /proc/acpi is a directory, divided into subdirectories for each power device (fan, battery, button, and so on). Each subdirectory gives information about its device. /proc/apm is a 'file' which has information about the power, such as charge, the state of the ac-adapter, and time untill battery charged/drained.

The /proc file system is also used by many parts of the kernel for input and output.