procfs

From ArchWiki

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Use Template:ic. (Discuss in Talk:Procfs)

The proc file system, also called procfs, is a pseudo file system that is usually mounted at /proc and contains information about the running system:

  • Processes, the most prominent use.
  • Kernel information and parameters.
  • System metrics, such as CPU usage.

Content

Kernel & system information

There are many files under /proc which provide a lot of information about the system as well as the kernel. There are too many to cover them all here, but some of them are listed below with brief information about what they are.

  • /proc/cpuinfo - informations about CPU
  • /proc/meminfo - information about the physical memory
  • /proc/vmstat - information about the virtual memory
  • /proc/mounts - information about the mounts
  • /proc/filesystems - information about filesystems that have been compiled into the kernel and whose kernel modules are currently loaded
  • /proc/uptime - current system uptime
  • /proc/cmdline - kernel command line

Processes

Inside /proc/pid is stored information about every process currently running. Below is an example showing some of the PIDs currently running:

$ ls -l /proc
total 0
dr-xr-xr-x  9 root    root                  0 Sep  8 18:17 1
dr-xr-xr-x  9 root    root                  0 Sep  9 03:02 10
dr-xr-xr-x  9 daemonx daemonx               0 Sep  9 03:02 1057
dr-xr-xr-x  9 daemonx daemonx               0 Sep  8 18:18 1077
dr-xr-xr-x  9 daemonx daemonx               0 Sep  9 03:02 1087
dr-xr-xr-x  9 root    root                  0 Sep  9 03:02 11
dr-xr-xr-x  9 daemonx daemonx               0 Sep  9 03:02 1103
dr-xr-xr-x  9 daemonx daemonx               0 Sep  9 03:02 1107
dr-xr-xr-x  9 daemonx daemonx               0 Sep  9 03:02 1159
dr-xr-xr-x  9 root    root                  0 Sep  9 03:02 12
dr-xr-xr-x  9 root    root                  0 Sep  9 03:02 124
dr-xr-xr-x  9 root    root                  0 Sep  9 03:02 125
dr-xr-xr-x  9 root    root                  0 Sep  9 03:02 127
dr-xr-xr-x  9 root    root                  0 Sep  9 03:02 128
...

Lets take for example pid 1057 and see what is inside:

$ ls -l /proc/1057
total 0
dr-xr-xr-x 2 daemonx daemonx 0 Sep  9 03:12 attr
-rw-r--r-- 1 daemonx daemonx 0 Sep  9 03:12 autogroup
-r-------- 1 daemonx daemonx 0 Sep  9 03:12 auxv
-r--r--r-- 1 daemonx daemonx 0 Sep  9 03:12 cgroup
--w------- 1 daemonx daemonx 0 Sep  9 03:12 clear_refs
-r--r--r-- 1 daemonx daemonx 0 Sep  9 03:12 cmdline
-rw-r--r-- 1 daemonx daemonx 0 Sep  9 03:12 comm
-rw-r--r-- 1 daemonx daemonx 0 Sep  9 03:12 coredump_filter
-r--r--r-- 1 daemonx daemonx 0 Sep  9 03:12 cpuset
lrwxrwxrwx 1 daemonx daemonx 0 Sep  9 03:12 cwd -> /home/daemonx
-r-------- 1 daemonx daemonx 0 Sep  9 03:12 environ
lrwxrwxrwx 1 daemonx daemonx 0 Sep  9 03:12 exe -> /usr/lib/gvfsd-metadata
dr-x------ 2 daemonx daemonx 0 Sep  9 03:12 fd
dr-x------ 2 daemonx daemonx 0 Sep  9 03:12 fdinfo
-rw-r--r-- 1 daemonx daemonx 0 Sep  9 03:12 gid_map
-r-------- 1 daemonx daemonx 0 Sep  9 03:12 io
-r--r--r-- 1 daemonx daemonx 0 Sep  9 03:12 latency
-r--r--r-- 1 daemonx daemonx 0 Sep  9 03:12 limits
-rw-r--r-- 1 daemonx daemonx 0 Sep  9 03:12 loginuid
dr-x------ 2 daemonx daemonx 0 Sep  9 03:12 map_files
-r--r--r-- 1 daemonx daemonx 0 Sep  9 03:12 maps
-rw------- 1 daemonx daemonx 0 Sep  9 03:12 mem
...

Some of the fields:

  • cmdline - arguments used to start program.
  • cwd - current working directory for the process.
  • environ - environment variables inside the process (zero-delimited).
  • fd/ - directory containing open file descriptors for the process.
  • exe - symbolic link to process executable.
  • maps - memory mapping of the process.
  • mem - virtual memory of the process.

Usage

You can interact with /proc contents as with regular files.

To read from a file:

$ cat /proc/cmdline

To write to a file:

# echo 1 > /proc/sys/kernel/sysrq

See also