procfs

From ArchWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements. See Help:Style for reference.Tango-edit-clear.png

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

The proc filesystem, also called procfs, 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

Also see proc(5).

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/vmstats - information about the virtual memory
  • /proc/mounts - information about the mounts(mount)
  • /proc/filesystems - information about active filesystems
  • /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's 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
  • 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

To read from proc file, we can use cat: cat /proc/cmdline (run as the regular user). To write to the file, we can use echo: echo 1 > /proc/sys/kernel/sysrq (run as the root user).