procfs

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 in the kernel. It can be used to obtain information about the system and to change certain kernel parameters at runtime (sysctl).

Many Unix-like operating systems support the proc filesystem, including Solaris, IRIX, Tru64 UNIX, BSD, Linux, IBM AIX, QNX, and Plan 9 from Bell Labs. 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.

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

4.4BSD cloned its implementation of /proc from Plan 9. As of February 2011, procfs is gradually becoming phased out in FreeBSD.[1] 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".[2]

Solaris

/proc in Solaris 2.6 was finished in 1996; the developers also cloned Plan 9.

Linux

The Linux implementation of /proc also clones that of Plan 9. Under Linux, /proc 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:

(Users may obtain the PID with a utility such as pgrep, pidof or ps:

$ ls -l /proc/$(pgrep -n python)/fd        # List all file descriptors of the most recently started `python' process
samtala 0
lrwx------ 1 baldur baldur 64 2011-03-18 12:31 0 -> /dev/pts/3
lrwx------ 1 baldur baldur 64 2011-03-18 12:31 1 -> /dev/pts/3
lrwx------ 1 baldur baldur 64 2011-03-18 12:31 2 -> /dev/pts/3
$ readlink /proc/$(pgrep -n python)/exe    # List executable used to launch the most recently started `python' process  
/usr/bin/python3.1

)

/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:

On multi-core CPUs, /proc/cpuinfo contains the fields for "siblings" and "cpu cores" which represent the following calculation is applied:[4]

"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.[5] 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 (/proc processes) package, and only function in conjunction with a mounted /proc.

Cobalt

Cobalt Networks added additional functions to /proc for their systems:

References

  1. "Why is procfs deprecated in favor of procstat?". freebsd.org.
  2. "Detailed changes between OpenBSD 5.6 and 5.7". openbsd.org.
  3. "3.2.2. /proc/buddyinfo". centos.org.
  4. Baron, Jason. "HT vs. dual-core".
  5. "Understanding Linux /proc/cpuinfo". richweb.com. Archived from the original on 2012-04-03. Retrieved 2015-04-21.
  6. Nguyen, Binh (2004-07-30). "Linux Filesystem Hierarchy". Binh Nguyen. p. 63. Retrieved 2016-07-18. /proc/kmsg[:] Messages output by the kernel. These are also routed to syslog.
This article is issued from Wikipedia - version of the 9/21/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.