procfs
Template:Short description Script error: No such module "Unsubst".
Script error: No such module "Unsubst".
The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory. Typically, it is mapped to a mount point named /proc at boot time. The proc file system acts as an interface to internal data structures about running processes in the kernel. In Linux, it can also be used to obtain information about the kernel and to change certain kernel parameters at runtime (sysctl).
Many Unix-like operating systems support the proc filesystem, including System V, Solaris, IRIX, Tru64 UNIX, BSD, Linux, IBM AIX,[1] QNX, and Plan 9 from Bell Labs. OpenBSD dropped support in version 5.7, released in May 2015. It is absent from HP-UX[1] and macOS.[2]
The Linux kernel extends it to non–process-related data.
The proc filesystem provides a method of communication between kernel space and user space. For example, the ps command on Plan 9 and the GNU version of the process reporting utility ps uses the proc file system to obtain its data, without using any specialized system calls.
History
UNIX 8th Edition
Tom J. Killian implemented the UNIX 8th Edition (V8) version of /proc: he presented a paper titled "Processes as Files" at USENIX in June 1984. The design of procfs aimed to replace the ptrace system call used for process tracing. Detailed documentation can be found in the proc(4) manual page.
SVR3
The original AT&T System V Release 3 (SVR3) operating system (available internally to AT&T in 1986 and generally in 1987) did not come with the /proc filesystem, but a subsequent incremental version of it did. It only contained files representing the processes rather than the now common subdirectories.
SVR4
Roger Faulkner and Ron Gomes ported V8 /proc to SVR4, and published a paper called "The Process File System and Process Model in UNIX System V" at USENIX in January 1991. This kind of procfs supported the creation of ps, but the files could only be accessed with functions read(), write(), and ioctl(). Between 1995 and 1996, Roger Faulkner created the procfs-2 interface for Solaris-2.6 that offers a structured /proc filesystem with sub-directories.
Plan 9
Plan 9 implemented a process file system, but went further than V8. V8's process file system implemented a single file per process. Plan 9 created a hierarchy of separate files to provide those functions, and made /proc a real part of the file system. Furthermore, Plan 9's approach to portability allows systems with different architectures and byte order to debug others' processes.
4.4BSD and derivatives
4.4BSD cloned its implementation of Page Template:Mono/styles.css has no content./proc from Plan 9.Script error: No such module "Unsubst". As of February 2011[update]Script error: No such module "Check for unknown parameters"., procfs is gradually becoming phased out in FreeBSD,[3] and it has turned to use the sysctl interface instead for process-related information. To provide binary compatibility with Linux user space programs, the FreeBSD kernel also provides linprocfs that is similar to the Linux procfs.[4] It was removed from OpenBSD in version 5.7, which was released in May 2015, because it "always suffered from race conditions and is now unused".[5] macOS did not implement procfs and user space programs have to use the sysctl interface for retrieving process data.[2]
Solaris
/proc in Solaris was available from the beginning (June 1992). Solaris 2.6 in 1996 introduced procfs2 from Roger Faulkner.
Linux
Linux first added a /proc filesystem in v0.97.3, September 1992, and first began expanding it to non-process related data in v0.98.6, December 1992.
As of 2020, the Linux implementation includes a directory for each running process, including kernel processes, in directories named Page Template:Mono/styles.css has no content./proc/PID, where Page Template:Mono/styles.css has no content.PID is the process number. Each directory contains information about one process, including:
- Page Template:Mono/styles.css has no content./proc/PID/cmdline, the command that originally started the process.
- Page Template:Mono/styles.css has no content./proc/PID/cwd, a symlink to the current working directory of the process.
- Page Template:Mono/styles.css has no content./proc/PID/environ contains the names and values of the environment variables that affect the process.
- Page Template:Mono/styles.css has no content./proc/PID/exe, a symlink to the original executable file, if it still exists (a process may continue running after its original executable has been deleted or replaced).
- Page Template:Mono/styles.css has no content./proc/PID/fd, a directory containing a symbolic link for each open file descriptor.
- Page Template:Mono/styles.css has no content./proc/PID/fdinfo, a directory containing entries which describe the position and flags for each open file descriptor.
- Page Template:Mono/styles.css has no content./proc/PID/maps, a text file containing information about mapped files and blocks (like heap and stack).
- Page Template:Mono/styles.css has no content./proc/PID/mem, a binary image representing the process's virtual memory, can only be accessed by a ptrace'ing process.
- Page Template:Mono/styles.css has no content./proc/PID/root, a symlink to the root path as seen by the process. For most processes this will be a link to / unless the process is running in a chroot jail.
- Page Template:Mono/styles.css has no content./proc/PID/status contains basic information about a process including its run state and memory usage.
- Page Template:Mono/styles.css has no content./proc/PID/task, a directory containing hard links to any tasks that have been started by this (i.e.: the parent) process.
(Users may obtain the PID with a utility such as pgrep, pidof or ps:
$ ls -l /proc/$(pgrep -n python3)/fd # List all file descriptors of the most recently started `python3' process
total 0
lrwx------ 1 baldur baldur 64 2020-03-18 12:31 0 -> /dev/pts/3
lrwx------ 1 baldur baldur 64 2020-03-18 12:31 1 -> /dev/pts/3
lrwx------ 1 baldur baldur 64 2020-03-18 12:31 2 -> /dev/pts/3
$ readlink /proc/$(pgrep -n python3)/exe # List executable used to launch the most recently started `python3' process
/usr/bin/python3.8
)
Page Template:Mono/styles.css has no content./proc also includes non-process-related system information, although in the 2.6 kernel much of that information moved to a separate pseudo-file system, sysfs, mounted under Page Template:Mono/styles.css has no content./sys:
- depending on the mode of power management (if at all), either directory, Page Template:Mono/styles.css has no content./proc/acpi or Page Template:Mono/styles.css has no content./proc/apm, which predate sysfs and contain various bits of information about the state of power management.
- Page Template:Mono/styles.css has no content./proc/buddyinfo, information about the buddy algorithm that handles memory fragmentation.[6]
- Page Template:Mono/styles.css has no content./proc/bus, containing directories representing various buses on the computer, such as PCI/USB. This has been largely superseded by sysfs under /sys/bus which is far more informative.
- Page Template:Mono/styles.css has no content./proc/fb, a list of the available framebuffers
- Page Template:Mono/styles.css has no content./proc/cmdline, giving the boot options passed to the kernel
- Script error: No such module "anchor". Page Template:Mono/styles.css has no content./proc/cpuinfo, containing information about the CPU, such as its vendor (and CPU family, model and model names which should allow users to identify the CPU) and its speed (CPU clockspeed), cache size, number of siblings, cores, and CPU flags. The format and available information is highly architecture-depended. On some architectures, Page Template:Mono/styles.css has no content./proc/cpuinfo includes a value for "bogomips", frequently misconstrued as a measure of CPU speed, like a benchmark, but it does not actually measure any sensible (for end-users) value at all. It occurs as a side-effect of kernel timer calibration and yields highly varying values depending on CPU type, even at equal clock speeds.
$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 16
model : 6
model name : AMD Athlon II X2 270 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 2000.000
cache size : 1024 KB
...
processor : 1
vendor_id : AuthenticAMD
cpu family : 16
model : 6
model name : AMD Athlon II X2 270 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 800.000
cache size : 1024 KB
...
On multi-core CPUs, /proc/cpuinfo contains the fields for "siblings" and "cpu cores" which represent the following calculation is applied:[7]
"siblings" = (HT per CPU package) * (# of cores per CPU package) "cpu cores" = (# of cores per CPU package)
A CPU package means physical CPU which can have multiple cores (single core for one, dual core for two, quad core for four). This allows a distinction between hyper-threading and dual-core, i.e. the number of hyper-threads per CPU package can be calculated by siblings / CPU cores. If both values for a CPU package are the same, then hyper-threading is not supported.[8] For instance, a CPU package with siblings=2 and "cpu cores"=2 is a dual-core CPU but does not support hyper-threading.
- Page Template:Mono/styles.css has no content./proc/crypto, a list of available cryptographic modules
- Page Template:Mono/styles.css has no content./proc/devices, a list of character and block devices sorted by device ID but giving the major part of the Page Template:Mono/styles.css has no content./dev name too
- Page Template:Mono/styles.css has no content./proc/diskstats, giving some information (including device numbers) for each of the logical disk devices
- Page Template:Mono/styles.css has no content./proc/filesystems, a list of the file systems supported by the kernel at the time of listing
- Page Template:Mono/styles.css has no content./proc/interrupts, Page Template:Mono/styles.css has no content./proc/iomem, Page Template:Mono/styles.css has no content./proc/ioports and the directory Page Template:Mono/styles.css has no content./proc/irq, giving some details about the devices (physical or logical) using the various system resources
- Page Template:Mono/styles.css has no content./proc/kmsg, holding messages output by the kernel[9]
- Page Template:Mono/styles.css has no content./proc/loadavg, containing stats about the current load average in the last minutes.
- Page Template:Mono/styles.css has no content./proc/meminfo, containing a summary of how the kernel is managing its memory.
- Page Template:Mono/styles.css has no content./proc/modules, one of the most important files in Page Template:Mono/styles.css has no content./proc, containing a list of the kernel modules currently loaded . It gives some indication (not always entirely correct) of dependencies.
- Page Template:Mono/styles.css has no content./proc/mounts, a symlink to self/mounts which contains a list of the currently mounted devices and their mount points (and which file system is in use and what mount options are in use).
- Page Template:Mono/styles.css has no content./proc/net/, a directory containing useful information about the network stack, in particular Page Template:Mono/styles.css has no content./proc/net/nf_conntrack, which lists existing network connections (particularly useful for tracking routing when iptables FORWARD is used to redirect network connections)
- Page Template:Mono/styles.css has no content./proc/partitions, a list of the device-numbers, their size and Page Template:Mono/styles.css has no content./dev names which the kernel has identified as existing partitions
- Page Template:Mono/styles.css has no content./proc/scsi, giving information about any devices connected via a SCSI or RAID controller
- a symbolic link to the current (traversing) process at Page Template:Mono/styles.css has no content./proc/self (i.e. Page Template:Mono/styles.css has no content./proc/PID/ where PID is that of the current process).
- Page Template:Mono/styles.css has no content./proc/slabinfo, listing statistics on the caches for frequently-used objects in the Linux kernel
- Page Template:Mono/styles.css has no content./proc/swaps, a list of the active swap partitions, their various sizes and priorities
- Access to dynamically configurable kernel options under Page Template:Mono/styles.css has no content./proc/sys. Under Page Template:Mono/styles.css has no content./proc/sys appear directories representing the areas of kernel, containing readable and writable virtual files.
For example, a commonly referenced virtual file is Page Template:Mono/styles.css has no content./proc/sys/net/ipv4/ip_forward, because it is necessary for routing firewalls or tunnels. The file contains either a '1' or a '0': if it is 1, the IPv4 stack forwards packets not meant for the local host, if it is 0 then it does not. - Page Template:Mono/styles.css has no content./proc/sysvipc, containing memory-sharing and inter-process communication (IPC) information.
- Page Template:Mono/styles.css has no content./proc/tty, containing information about terminals; Page Template:Mono/styles.css has no content./proc/tty/driver contains a list of TTY drivers and their usage[10]
- Page Template:Mono/styles.css has no content./proc/uptime, the length of time the kernel has been running since boot and spent in idle mode (both in seconds)
- Page Template:Mono/styles.css has no content./proc/version, containing the Linux kernel version, distribution number, gcc version number (used to build the kernel) and any other pertinent information relating to the version of the kernel currently running
- other files depending on various hardware, module configurations, and changes to the kernel.
The basic utilities that use /proc under Linux come in the procps (Page Template:Mono/styles.css has no content./proc processes) package, and only function in conjunction with a mounted Page Template:Mono/styles.css has no content./proc.
CYGWIN
Cygwin implemented a procfs that is basically the same as the Linux procfs.
References
Page Template:Reflist/styles.css has no content.
- ↑ a b Script error: No such module "citation/CS1".
- ↑ a b Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
- ↑ Script error: No such module "citation/CS1".
Script error: No such module "Check for unknown parameters".
Sources
- Unix 8th Edition proc(2) manual page - Description of the original procfs.
- Plan 9 procfs manual page - Plan 9 greatly expanded the procfs concept, providing a much expanded interface to control and manipulate processes.
- Linux Manual Pages Proc(5) Linux manual documentation for procfs
- Documentation/filesystems/proc.txt Linux kernel documentation for procfs
External links
- A brief history of /proc Eric Schrock's Weblog
- Access the Linux kernel using the Procfs An IBM developerWorks article by M. Tim Jones
- Linux-Filesystem-Hierarchy Linux Documentation Project
- Discover the possibilities of the /proc directory by Federico Kereki
Script error: No such module "Navbox". Template:Operating system