Procfs Explained

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 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 from Plan 9., procfs is gradually becoming phased out in FreeBSD,[2] 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.[3] 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".[4] macOS did not implement procfs and user space programs have to use the sysctl interface for retrieving process data.[5]

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, where is the process number. Each directory contains information about one process, including:

(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' processtotal 0lrwx------ 1 baldur baldur 64 2020-03-18 12:31 0 -> /dev/pts/3lrwx------ 1 baldur baldur 64 2020-03-18 12:31 1 -> /dev/pts/3lrwx------ 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)

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 :

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.

The basic utilities that use /proc under Linux come in the procps (processes) package, and only function in conjunction with a mounted .

CYGWIN

Cygwin implemented a procfs that is basically the same as the Linux procfs.

Sources

External links

Notes and References

  1. Book: Nemeth . Evi . UNIX and Linux System Administration Handbook . Snyder . Garth . Hein . Trent R. . Whaley . Ben . 2010-07-14 . Pearson Education . 978-0-13-211736-4 . 136 . en.
  2. Web site: Why is procfs deprecated in favor of procstat?. freebsd.org. 22 February 2011 .
  3. Web site: linprocfs(5) . FreeBSD Manual Pages . The FreeBSD Project . 2021-06-12 . en . 2019-11-13.
  4. Web site: Detailed changes between OpenBSD 5.6 and 5.7. openbsd.org.
  5. Web site: Amit Singh . /proc on Mac OS X . Mac OS X Internals: The Book . 2021-07-10 . https://web.archive.org/web/20120504052329/http://osxbook.com/book/bonus/ancient/procfs/ . 2012-05-04 . 2003.
  6. Web site: 3.2.2. /proc/buddyinfo . centos.org . 23 May 2011 . https://web.archive.org/web/20130902032109/http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-proc-buddyinfo.html . 2 September 2013 . dead .
  7. Web site: Baron . Jason . HT vs. dual-core . 28 June 2011 . 13 May 2016 . https://web.archive.org/web/20160513191756/http://www.redhat.com/archives/nahant-list/2006-January/msg00176.html . dead .
  8. Web site: Understanding Linux /proc/cpuinfo . https://web.archive.org/web/20120403230159/http://www.richweb.com/cpu_info . 2015-04-21 . 2012-04-03 . richweb.com.
  9. Web site: Linux Filesystem Hierarchy . Nguyen . Binh . 2004-07-30 . Binh Nguyen . 63 . 2016-07-18 . /proc/kmsg[:] Messages output by the kernel. These are also routed to syslog..
  10. Web site: The /proc filesystem . Linux Kernel documentation . 9 August 2024.