Revision as of 02:39, 23 June 2009 editTriskelios (talk | contribs)143 edits Clean up links, add IRIX and Tru64 as systems with procfs, add link for /proc history← Previous edit | Latest revision as of 14:44, 9 August 2024 edit undo82.6.216.183 (talk) Clarify /proc/tty description slightly and add link to terminal emulator article | ||
(160 intermediate revisions by more than 100 users not shown) | |||
Line 1: | Line 1: | ||
{{short description|Filesystem in Unix-like operating systems}} | |||
{{lowercase|title=procfs}} | |||
{{more citations needed|date=March 2010}} | |||
<!-- --> | |||
{{lowercase title|title=procfs}} | |||
On many ]-like computer systems, '''procfs''', short for ] ], consists of a pseudo file system (a file system dynamically generated at boot) used to access process information from the ]. The file system is often mounted at the <code>/proc</code> ]. Because <tt>/proc</tt> is not a real file system, it consumes no storage space and only a limited amount of memory. | |||
{{Use dmy dates|date=July 2021}} | |||
The '''proc filesystem''' ('''procfs''') is a special filesystem in ] operating systems that presents information about ]es 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 ] methods or direct access to ] memory. Typically, it is mapped to a ] named ''/proc'' at boot time. The proc file system acts as an interface to internal data structures about running processes in the kernel. In ], it can also be used to obtain information about the kernel and to change certain kernel parameters at runtime (]). | |||
The following operating environments support procfs: | |||
Many Unix-like operating systems support the proc filesystem, including ], ], ], ], ], ], ],<ref name=":0">{{Cite book |last1=Nemeth |first1=Evi |url=https://books.google.com/books?id=rgFIAnLjb1wC&pg=PA136 |title=UNIX and Linux System Administration Handbook |last2=Snyder |first2=Garth |last3=Hein |first3=Trent R. |last4=Whaley |first4=Ben |date=2010-07-14 |publisher=Pearson Education |isbn=978-0-13-211736-4 |pages=136 |language=en}}</ref> ], and ]. ] dropped support in version 5.7, released in May 2015. It is absent from ]<ref name=":0" /> and ].<ref name=":1" /> | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] (which extends it to non-process-related data) | |||
* ] (which bases its implementation on Linux to improve compatibility) | |||
* ] | |||
* ] (where it originated) | |||
The ] extends it to non–process-related data. | |||
{{Expand-section|date=January 2007}} | |||
The proc filesystem provides a method of communication between ] and ]. For example, the ] version of the process reporting utility ] uses the proc file system to obtain its data, without using any specialized ]s. | |||
== History == | == History == | ||
=== UNIX 8th Edition === | === UNIX 8th Edition === | ||
] implemented the ] (V8) version of ''/proc'': he presented a paper titled at ] in June 1984. The design of procfs aimed to replace the '']'' system call used for process tracing. Detailed documentation can be found in the . | |||
=== SVR3 === | |||
] implemented the ] version of <code>/proc</code>: he presented a paper titled "Processes as Files" at ] in June 1984. The design of procfs aimed to replace the '']'' system call used for process tracing. | |||
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 === | === SVR4 === | ||
] and ] ported V8 |
] and ] ported V8 ''/proc'' to ], and published a paper called at USENIX in January 1991. This kind of procfs supported the creation of '']'', but the files could only be accessed with functions ''read()'', ''write()'', and '']()''. 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 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. | ||
=== 4.4BSD === | === 4.4BSD and derivatives === | ||
] cloned its implementation of {{Mono|/proc}} from Plan 9.{{citation needed|date=December 2010}} {{As of|2011|2}}, procfs is gradually becoming phased out in FreeBSD,<ref>{{cite web|url=http://lists.freebsd.org/pipermail/freebsd-fs/2011-February/010760.html|title=Why is procfs deprecated in favor of procstat?|work=freebsd.org|date=22 February 2011 }}</ref> and it has turned to use the '']'' interface instead for process-related information. | |||
] cloned its implementation of <code>/proc</code> from Plan 9. Note that in FreeBSD procfs is being gradually phased out. | |||
To provide binary compatibility with Linux user space programs, the FreeBSD kernel also provides '''linprocfs''' that is similar to the Linux procfs.<ref>{{cite web |title=linprocfs(5) |url=https://www.freebsd.org/cgi/man.cgi?query=linprocfs&apropos=0&sektion=5&manpath=FreeBSD+13.0-RELEASE&arch=default&format=html |website=FreeBSD Manual Pages |publisher=The FreeBSD Project |accessdate=2021-06-12 |language=en |date=2019-11-13}}</ref> | |||
It was removed from ] in version 5.7, which was released in May 2015, because it "always suffered from race conditions and is now unused".<ref>{{cite web|url=http://www.openbsd.org/plus57.html|title=Detailed changes between OpenBSD 5.6 and 5.7|work=openbsd.org}}</ref> | |||
] did not implement procfs and user space programs have to use the ''sysctl'' interface for retrieving process data.<ref name=":1">{{cite web |author1=Amit Singh |title=/proc on Mac OS X |url=http://osxbook.com/book/bonus/ancient/procfs/ |website=Mac OS X Internals: The Book |access-date=2021-07-10 |archive-url=https://web.archive.org/web/20120504052329/http://osxbook.com/book/bonus/ancient/procfs/ |archive-date=2012-05-04 |date=2003}}</ref> | |||
=== Solaris === | === Solaris === | ||
/proc in Solaris was available from the beginning (June 1992). Solaris 2.6 in 1996 introduced procfs2 from Roger Faulkner. | |||
Solaris 2.6's <code>/proc</code> (finished in 1996) also cloned Plan 9. | |||
=== Linux === | === Linux === | ||
Linux first added a /proc filesystem in , September 1992, and first began expanding it to non-process related data in v0.98.6, December 1992. | |||
The Linux implementation of <code>/proc</code> also clones that of ]. Under Linux, <code>/proc</code> includes a directory for each running process (including ] processes) at <code>/proc/''PID''</code>, containing information about that process, notably including: | |||
* <code>/proc/''PID''/cmdline</code>, which contains the command which originally started the process. | |||
* <code>/proc/''PID''/cwd</code>, a ] to the ] of the process. | |||
* <code>/proc/''PID''/exe</code>, a symlink to the original ], if it still exists (a process may continue running after its original executable has been deleted or replaced). | |||
* <code>/proc/''PID''/fd</code>, a directory containing a symbolic link for each open file descriptor. | |||
* <code>/proc/''PID''/root</code>, 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 ]. | |||
* <code>/proc/''PID''/status</code>, a file containing basic information about a process including its run state and memory usage. | |||
* <code>/proc/''PID''/task</code>, a directory containing ] to any tasks that have been started by this (i.e.: the parent) process. | |||
* <code>/proc/''PID''/maps</code>, the memory map showing which addresses currently visible to that process are mapped to which regions in RAM or to files. | |||
As of 2020, the Linux implementation includes a directory for each running process, including ] processes, in directories named {{Mono|/proc/PID}}, where {{Mono|PID}} is the process number. Each directory contains information about one process, including: | |||
It also includes non-process-related system information, although in the 2.6 kernel much of that information moved to a separate pseudo-file system, ], mounted under <code>/sys</code>: | |||
* {{Mono|/proc/PID/cmdline}}, the command that originally started the process. | |||
* {{Mono|/proc/PID/cwd}}, a ] to the ] of the process. | |||
* {{Mono|/proc/PID/environ}} contains the names and values of the environment variables that affect the process. | |||
* {{Mono|/proc/PID/exe}}, a symlink to the original ] file, if it still exists (a process may continue running after its original executable has been deleted or replaced). | |||
* {{Mono|/proc/PID/fd}}, a directory containing a symbolic link for each open ]. | |||
* {{Mono|/proc/PID/fdinfo}}, a directory containing entries which describe the position and flags for each open file descriptor. | |||
* {{Mono|/proc/PID/maps}}, a text file containing information about ] files and blocks (like heap and stack). | |||
* {{Mono|/proc/PID/mem}}, a binary image representing the process's ], can only be accessed by a ]'ing process. | |||
* {{Mono|/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 ] jail. | |||
* {{Mono|/proc/PID/status}} contains basic information about a process including its run state and memory usage. | |||
* {{Mono|/proc/PID/task}}, a directory containing ]s to any tasks that have been started by this (i.e.: the parent) process. | |||
(Users may obtain the ] with a utility such as ], ] or ]: | |||
* depending on the mode of power management (if at all), either directory, <code>/proc/acpi</code> or <code>/proc/apm</code>, which predate sysfs and contain various bits of information about the state of power management. | |||
<syntaxhighlight lang="console"> | |||
* <code>/proc/bus</code>, containing directories representing various buses on the computer, such as input/]/]. This has been largely superseded by sysfs under /sys/bus which is far more informative. | |||
$ ls -l /proc/$(pgrep -n python3)/fd # List all file descriptors of the most recently started `python3' process | |||
* <code>/proc/fb</code>, a list of the available framebuffers | |||
total 0 | |||
* <code>/proc/cmdline</code>, giving the boot options passed to the kernel | |||
lrwx------ 1 baldur baldur 64 2020-03-18 12:31 0 -> /dev/pts/3 | |||
* <code>/proc/cpuinfo</code>, containing information about the ], such as its vendor (and CPU family, model and model names which should allow users to identify the CPU) and its speed (CPU ]), cache size, number of siblings, cores, and CPU flags. It contains a value called "]", frequently misunderstood as measure CPU-speed like a benchmark, while it doesn't 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. | |||
lrwx------ 1 baldur baldur 64 2020-03-18 12:31 1 -> /dev/pts/3 | |||
* <code>/proc/crypto</code>, a list of available cryptographic modules | |||
lrwx------ 1 baldur baldur 64 2020-03-18 12:31 2 -> /dev/pts/3 | |||
* <code>/proc/devices</code>, a list of character and block devices sorted by device ID but giving the major part of the <code>/dev</code> name too | |||
$ readlink /proc/$(pgrep -n python3)/exe # List executable used to launch the most recently started `python3' process | |||
* <code>/proc/diskstats</code>, giving some information (including device numbers) for each of the logical disk devices | |||
/usr/bin/python3.8 | |||
* <code>/proc/filesystems</code>, a list of the file systems supported by the kernel at the time of listing | |||
</syntaxhighlight>) | |||
* <code>/proc/interrupts</code>, <code>/proc/iomem</code>, <code>/proc/ioports</code> and the directory <code>/proc/irq</code>, giving some self-explanatory details about the devices (physical or logical) using the various system resources | |||
* <code>/proc/meminfo</code>, containing a summary of how the kernel is managing its memory. | |||
{{Mono|/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, ], mounted under {{Mono|/sys}}: | |||
* <code>/proc/modules</code>, one of the most important files in <code>/proc</code>, containing a list of the kernel modules currently loaded . It gives some indication ( not always entirely correct) of dependencies. | |||
* <code>/proc/mounts</code>, 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). | |||
* depending on the mode of power management (if at all), either directory, {{Mono|/proc/acpi}} or {{Mono|/proc/apm}}, which predate sysfs and contain various bits of information about the state of power management. | |||
* <code>/proc/net</code>, a directory containing a lot of really useful information about the network stack, in particular nf_conntrack which lists existing network connections (particularly useful for tracking routing when ] FORWARD is used to redirect network connections). | |||
* {{Mono|/proc/buddyinfo}}, information about the ] that handles memory fragmentation.<ref>{{cite web | |||
* <code>/proc/partitions</code>, a list of the device-numbers, their size and <code>/dev</code> names which the kernel has identified as existing ] (for example if /dev/sda contains a partition table, then /dev/sda1 and others will appear as available partitions). Note that if a partition isn't listed in this file, then a patched version of losetup is around which can essentially mount the partition and connect /dev/loop devices to the various partitions (though it is not certain if these will then appear in <code>/proc/partitions</code>). | |||
|url=http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-proc-buddyinfo.html | |||
* <code>/proc/scsi</code>, giving information about any devices connected via a ] or ] controller | |||
|title=3.2.2. /proc/buddyinfo | |||
* a symbolic link to the current (traversing) process at <code>/proc/self</code> (i.e. <code>/proc/''PID''/</code> where ] is that of the current process). | |||
|work=centos.org | |||
* <code>/proc/slabinfo</code>, listing statistics on the caches for frequently-used objects in the Linux kernel | |||
|access-date=23 May 2011 | |||
* <code>/proc/swaps</code>, a list of the active swap partitions, their various sizes and priorities | |||
|archive-url=https://web.archive.org/web/20130902032109/http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-proc-buddyinfo.html | |||
* Access to dynamically-configurable kernel options under <code>/proc/sys</code>. Under <code>/proc/sys</code> appear directories representing the areas of kernel, containing readable and writable virtual files.<br> For example, a commonly referenced virtual file is <code>/proc/sys/net/ipv4/ip_forward</code>, because it is necessary for routing firewalls or tunnels. The file contains either a '1' or a '0': if it is 1 then the IPv4 stack will forward packets not meant for the local host, if it is 0 then it will not. | |||
|archive-date=2 September 2013 | |||
* <code>/proc/sysvipc</code>, containing memory sharing and ] information. | |||
|url-status=dead | |||
* <code>/proc/tty</code>, containing information about the current terminals; <code>/proc/tty/driver</code> looks to be a list of the different types of ] available each of which is a list of those of each type | |||
}}</ref> | |||
* <code>/proc/uptime</code>, the length of time the kernel has been running since boot and spent in idle mode (both in seconds) | |||
* {{Mono|/proc/bus}}, containing directories representing various buses on the computer, such as ]/]. This has been largely superseded by ] under /sys/bus which is far more informative. | |||
* <code>/proc/version</code>, containing the Linux kernel version, distribution number, ] version number (used to build the kernel) and any other pertinent information relating to the version of the kernel currently running | |||
* {{Mono|/proc/fb}}, a list of the available framebuffers | |||
* {{Mono|/proc/cmdline}}, giving the boot options passed to the kernel | |||
* {{anchor|cpuinfo}} {{Mono|/proc/cpuinfo}}, containing information about the ], such as its vendor (and CPU family, model and model names which should allow users to identify the CPU) and its speed (CPU ]), cache size, number of siblings, cores, and ]. The format and available information is highly architecture-depended. On some architectures, {{Mono|/proc/cpuinfo}} includes a value for "]", 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. | |||
{{sxhl|2=console| | |||
$ cat /proc/cpuinfo | |||
processor : 0 | |||
vendor_id : AuthenticAMD | |||
cpu family : 16 | |||
model : 6 | |||
model name : AMD Athlon(tm) 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(tm) 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:<ref>{{cite web | |||
|last=Baron | |||
|first=Jason | |||
|title=HT vs. dual-core | |||
|url=http://www.redhat.com/archives/nahant-list/2006-January/msg00176.html | |||
|access-date=28 June 2011 | |||
|archive-date=13 May 2016 | |||
|archive-url=https://web.archive.org/web/20160513191756/http://www.redhat.com/archives/nahant-list/2006-January/msg00176.html | |||
|url-status=dead | |||
}}</ref> | |||
<pre>"siblings" = (HT per CPU package) * (# of cores per CPU package) | |||
"cpu cores" = (# of cores per CPU package)</pre> | |||
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 ] 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.<ref>{{cite web | |||
|title=Understanding Linux /proc/cpuinfo | |||
|url=http://www.richweb.com/cpu_info | |||
|archive-url=https://web.archive.org/web/20120403230159/http://www.richweb.com/cpu_info | |||
|access-date=2015-04-21 | |||
|archive-date=2012-04-03 | |||
|website=richweb.com | |||
}}</ref> For instance, a CPU package with siblings=2 and "cpu cores"=2 is a dual-core CPU but does not support hyper-threading. | |||
* {{Mono|/proc/crypto}}, a list of available cryptographic modules | |||
* {{Mono|/proc/devices}}, a list of character and block devices sorted by device ID but giving the major part of the {{Mono|/dev}} name too | |||
* {{Mono|/proc/diskstats}}, giving some information (including device numbers) for each of the logical disk devices | |||
* {{Mono|/proc/filesystems}}, a list of the file systems supported by the kernel at the time of listing | |||
* {{Mono|/proc/interrupts}}, {{Mono|/proc/iomem}}, {{Mono|/proc/ioports}} and the directory {{Mono|/proc/irq}}, giving some details about the devices (physical or logical) using the various ]s | |||
* {{Mono|/proc/kmsg}}, holding messages output by the kernel<ref> | |||
{{cite web | |||
| url = https://books.google.com/books?id=wLJWBQAAQBAJ | |||
| title = Linux Filesystem Hierarchy | |||
| last1 = Nguyen | |||
| first1 = Binh | |||
| date = 2004-07-30 | |||
| publisher = Binh Nguyen | |||
| page = 63 | |||
| access-date = 2016-07-18 | |||
| quote = /proc/kmsg Messages output by the kernel. These are also routed to syslog. | |||
}} | |||
</ref> | |||
* {{Mono|/proc/loadavg}}, containing stats about the current ] average in the last minutes. | |||
* {{Mono|/proc/meminfo}}, containing a summary of how the kernel is managing its memory. | |||
* {{Mono|/proc/modules}}, one of the most important files in {{Mono|/proc}}, containing a list of the kernel modules currently loaded . It gives some indication (not always entirely correct) of dependencies. | |||
* {{Mono|/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). | |||
* {{Mono|/proc/net/}}, a directory containing useful information about the network stack, in particular {{Mono|/proc/net/nf_conntrack}}, which lists existing network connections (particularly useful for tracking routing when ] FORWARD is used to redirect network connections) | |||
* {{Mono|/proc/partitions}}, a list of the device-numbers, their size and {{Mono|/dev}} names which the kernel has identified as existing ] | |||
* {{Mono|/proc/scsi}}, giving information about any devices connected via a ] or ] controller | |||
* a symbolic link to the current (traversing) process at {{Mono|/proc/self}} (i.e. {{Mono|/proc/PID/}} where ] is that of the current process). | |||
* {{Mono|/proc/slabinfo}}, listing statistics on the caches for frequently-used objects in the Linux kernel | |||
* {{Mono|/proc/swaps}}, a list of the active swap partitions, their various sizes and priorities | |||
* Access to dynamically configurable kernel options under {{Mono|/proc/sys}}. Under {{Mono|/proc/sys}} appear directories representing the areas of kernel, containing readable and writable ]s.<br> For example, a commonly referenced virtual file is {{Mono|/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. | |||
* {{Mono|/proc/sysvipc}}, containing memory-sharing and ] (IPC) information. | |||
* {{Mono|/proc/tty}}, containing information about ]; {{Mono|/proc/tty/driver}} contains a list of TTY drivers and their usage<ref>{{cite web |title=The /proc filesystem |url=https://www.kernel.org/doc/html/latest/filesystems/proc.html#tty-info-in-proc-tty |website=Linux Kernel documentation |access-date=9 August 2024}}</ref> | |||
* {{Mono|/proc/uptime}}, the length of time the kernel has been running since boot and spent in idle mode (both in seconds) | |||
* {{Mono|/proc/version}}, containing the Linux kernel version, distribution number, ] 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. | * other files depending on various hardware, module configurations, and changes to the kernel. | ||
The basic utilities that use /proc under Linux come in the ] (/proc processes) package, and only function in conjunction with a mounted |
The basic utilities that use /proc under Linux come in the ] ({{Mono|/proc}} processes) package, and only function in conjunction with a mounted {{Mono|/proc}}. | ||
=== CYGWIN === | |||
The procfs plays an important role in moving functionality from ] to ]. For example the ] version of <code>]</code> operates entirely in user mode, using the procfs to obtain its data. | |||
] implemented a procfs that is basically the same as the Linux procfs. | |||
== |
==References== | ||
{{Reflist}} | |||
==Sources== | |||
Note that ] boxes also include a few additions to <code>/proc</code>: | |||
* - Description of the original procfs. | |||
* <code>/proc/cobalt</code>, a directory containing cobalt-specific things like the serial number and the systype (system type). | |||
* - Plan 9 greatly expanded the procfs concept, providing a much expanded interface to control and manipulate processes. | |||
* <code>/proc/lcd</code>, a read/writable file containing the contents of the front-panel LCD screen. Echoing text to this file changes that on the front panel. | |||
* Linux manual documentation for procfs | |||
* Linux kernel documentation for procfs | |||
== External links == | == External links == | ||
* Eric Schrock's Weblog | * Eric Schrock's Weblog | ||
* An IBM developerWorks article by M. Tim Jones | * An IBM developerWorks article by M. Tim Jones | ||
* Linux Documentation Project | * Linux Documentation Project | ||
* by Federico Kereki | |||
{{File systems}} | |||
==References== | |||
{{Operating system}} | |||
{{Reflist}} | |||
* Linux kernel documentation for procfs | |||
] | ] | ||
] | ] | ||
] | ] | ||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] |
Latest revision as of 14:44, 9 August 2024
Filesystem in Unix-like operating systemsThis article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Procfs" – news · newspapers · books · scholar · JSTOR (March 2010) (Learn how and when to remove this message) |
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, QNX, and Plan 9 from Bell Labs. OpenBSD dropped support in version 5.7, released in May 2015. It is absent from HP-UX and macOS.
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 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.
4.4BSD and derivatives
4.4BSD cloned its implementation of /proc from Plan 9. As of February 2011, procfs is gradually becoming phased out in FreeBSD, 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. 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". macOS did not implement procfs and user space programs have to use the sysctl interface for retrieving process data.
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 /proc/PID, where PID is the process number. Each directory contains information about one process, including:
- /proc/PID/cmdline, the command that originally started the process.
- /proc/PID/cwd, a symlink to the current working directory of the process.
- /proc/PID/environ contains the names and values of the environment variables that affect the process.
- /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).
- /proc/PID/fd, a directory containing a symbolic link for each open file descriptor.
- /proc/PID/fdinfo, a directory containing entries which describe the position and flags for each open file descriptor.
- /proc/PID/maps, a text file containing information about mapped files and blocks (like heap and stack).
- /proc/PID/mem, a binary image representing the process's virtual memory, can only be accessed by a ptrace'ing process.
- /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.
- /proc/PID/status contains basic information about a process including its run state and memory usage.
- /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
)
/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 /sys:
- depending on the mode of power management (if at all), either directory, /proc/acpi or /proc/apm, which predate sysfs and contain various bits of information about the state of power management.
- /proc/buddyinfo, information about the buddy algorithm that handles memory fragmentation.
- /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.
- /proc/fb, a list of the available framebuffers
- /proc/cmdline, giving the boot options passed to the kernel
- /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, /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(tm) 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(tm) 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:
"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. For instance, a CPU package with siblings=2 and "cpu cores"=2 is a dual-core CPU but does not support hyper-threading.
- /proc/crypto, a list of available cryptographic modules
- /proc/devices, a list of character and block devices sorted by device ID but giving the major part of the /dev name too
- /proc/diskstats, giving some information (including device numbers) for each of the logical disk devices
- /proc/filesystems, a list of the file systems supported by the kernel at the time of listing
- /proc/interrupts, /proc/iomem, /proc/ioports and the directory /proc/irq, giving some details about the devices (physical or logical) using the various system resources
- /proc/kmsg, holding messages output by the kernel
- /proc/loadavg, containing stats about the current load average in the last minutes.
- /proc/meminfo, containing a summary of how the kernel is managing its memory.
- /proc/modules, one of the most important files in /proc, containing a list of the kernel modules currently loaded . It gives some indication (not always entirely correct) of dependencies.
- /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).
- /proc/net/, a directory containing useful information about the network stack, in particular /proc/net/nf_conntrack, which lists existing network connections (particularly useful for tracking routing when iptables FORWARD is used to redirect network connections)
- /proc/partitions, a list of the device-numbers, their size and /dev names which the kernel has identified as existing partitions
- /proc/scsi, giving information about any devices connected via a SCSI or RAID controller
- a symbolic link to the current (traversing) process at /proc/self (i.e. /proc/PID/ where PID is that of the current process).
- /proc/slabinfo, listing statistics on the caches for frequently-used objects in the Linux kernel
- /proc/swaps, a list of the active swap partitions, their various sizes and priorities
- Access to dynamically configurable kernel options under /proc/sys. Under /proc/sys appear directories representing the areas of kernel, containing readable and writable virtual files.
For example, a commonly referenced virtual file is /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. - /proc/sysvipc, containing memory-sharing and inter-process communication (IPC) information.
- /proc/tty, containing information about terminals; /proc/tty/driver contains a list of TTY drivers and their usage
- /proc/uptime, the length of time the kernel has been running since boot and spent in idle mode (both in seconds)
- /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 (/proc processes) package, and only function in conjunction with a mounted /proc.
CYGWIN
Cygwin implemented a procfs that is basically the same as the Linux procfs.
References
- ^ Nemeth, Evi; Snyder, Garth; Hein, Trent R.; Whaley, Ben (14 July 2010). UNIX and Linux System Administration Handbook. Pearson Education. p. 136. ISBN 978-0-13-211736-4.
- ^ Amit Singh (2003). "/proc on Mac OS X". Mac OS X Internals: The Book. Archived from the original on 4 May 2012. Retrieved 10 July 2021.
- "Why is procfs deprecated in favor of procstat?". freebsd.org. 22 February 2011.
- "linprocfs(5)". FreeBSD Manual Pages. The FreeBSD Project. 13 November 2019. Retrieved 12 June 2021.
- "Detailed changes between OpenBSD 5.6 and 5.7". openbsd.org.
- "3.2.2. /proc/buddyinfo". centos.org. Archived from the original on 2 September 2013. Retrieved 23 May 2011.
- Baron, Jason. "HT vs. dual-core". Archived from the original on 13 May 2016. Retrieved 28 June 2011.
- "Understanding Linux /proc/cpuinfo". richweb.com. Archived from the original on 3 April 2012. Retrieved 21 April 2015.
-
Nguyen, Binh (30 July 2004). "Linux Filesystem Hierarchy". Binh Nguyen. p. 63. Retrieved 18 July 2016.
/proc/kmsg Messages output by the kernel. These are also routed to syslog.
- "The /proc filesystem". Linux Kernel documentation. Retrieved 9 August 2024.
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
File systems | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Disk and non-rotating |
| ||||||||||
NAS | |||||||||||
Specialized |
| ||||||||||
Types | |||||||||||
Features |
| ||||||||||
Interfaces | |||||||||||
Lists | |||||||||||
Layouts |
Operating systems | |||||
---|---|---|---|---|---|
General | |||||
Variants | |||||
Kernel |
| ||||
Process management |
| ||||
Memory management, resource protection | |||||
Storage access, file systems | |||||
Supporting concepts |