procfs

procfs (or the proc filesystem) 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.

Operating systems that support the proc filesystem include, but are not limited to:

The proc filesystem helps to move functionality from kernel space to user space. For example, the GNU version of ps operates entirely in user mode, using the procfs to obtain its data.

Contents

History

UNIX 8th Edition

Tom J. Killian implemented the UNIX 8th Edition 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 could 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().

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. Note that in FreeBSD procfs is being gradually phased out.

Solaris

Solaris 2.6's /proc (finished in 1996) 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) at /proc/PID, containing information about that process, notably including:

Obtaining the PID can be done with utilities like 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

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, sysfs, mounted under /sys:

On multi-core CPUs, /proc/cpuinfo contains the two fields "siblings" and "cpu cores" whereas the following calculation is applied[2]:

"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 none, dual core for two, quad core for four). This allows to better distinguish between HT and dual-core, i.e. the number of HT 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.[3] For instance, a CPU package with siblings=2 and "cpu cores"=2 is a dual-core CPU but doesn't support HT.

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

External links