What is Procfs?
Procfs or "/proc" is a special filesystem under Linux that is used to present process information and kernel processes. Although "/proc" is still used widely, much of the information found on systems running with a kernel level of 2.6 and above have been moved to another pseudo filesystem called "sysfs" which is generally mounted under "/sys". "/proc" is stored in memory, unlike other filesystems, which are stored on disk. If you list the "/proc" filesystem, you will notice that the majority of files are of a "0" byte length. However, if you view the contents of the file, you will see that there is quite a substantial amount of information within.
$ file /proc/uptime
/proc/uptime: empty
$ cat /proc/uptime
5151.72 2053.73
Below is an example of "/proc" found on a Linux Mint 20 system. The trailing backslash "/" signifies a directory:
$ pwd
/proc
$ ls -F
1/ 147165/ 247/ 330/ 5818/ 6097/ 810/ driver/
10/ 147168/ 24756/ 332/ 5822/ 6103/ 811/ execdomains
1025/ 147195/ 24818/ 34/ 5845/ 6104/ 82/ fb
1036/ 147198/ 25/ 3409/ 5848/ 6114/ 820/ filesystems
1073/ 15/ 251/ 3410/ 59/ 612/ 821/ fs/
1077/ 150/ 259/ 3411/ 5918/ 613/ 822/ interrupts
1092/ 152/ 26/ 35/ 5932/ 614/ 83/ iomem
11/ 153/ 26404/ 3511/ 5937/ 6142/ 83611/ ioports
1108/ 155/ 26408/ 3512/ 5940/ 6154/ 84/ irq/
1113/ 15542/ 26410/ 3597/ 5951/ 61546/ 85/ kallsyms
1119/ 156/ 26413/ 36/ 5952/ 6162/ 854/ kcore
113589/ 157/ 265/ 3689/ 5955/ 6166/ 86/ keys
1140/ 15770/ 26541/ 3731/ 5956/ 6175/ 87/ key-users
1143/ 15772/ 268/ 38/ 5960/ 6176/ 88/ kmsg
115269/ 158/ 269/ 39/ 5974/ 6178/ 89/ kpagecgroup
116860/ 159/ 27/ 394/ 5976/ 6180/ 9/ kpagecount
116889/ 16/ 270/ 395/ 5978/ 6184/ 90/ kpageflags
12/ 161159/ 271/ 4/ 5987/ 6185/ 932/ loadavg
126456/ 16190/ 272/ 40/ 5988/ 62/ 933/ locks
126458/ 16192/ 273/ 41/ 5989/ 6237/ 938/ mdstat
129644/ 16195/ 274/ 42/ 5990/ 6239/ 939/ meminfo
13/ 16198/ 276/ 433/ 5992/ 6242/ 942/ misc
1305/ 16220/ 277/ 44/ 59956/ 6254/ 943/ modules
1337/ 16224/ 278/ 443/ 5997/ 6259/ 945/ mounts@
134396/ 16234/ 28/ 45/ 6/ 6260/ 946/ mtrr
137/ 16246/ 280/ 46/ 60/ 6268/ 953/ net@
138/ 16473/ 281/ 47/ 6001/ 63/ 956/ pagetypeinfo
139/ 165866/ 29/ 48/ 6003/ 64/ 959/ partitions
14/ 165895/ 3/ 485/ 6004/ 64718/ 96/ pressure/
140/ 166/ 30/ 499/ 6005/ 65/ 962/ sched_debug
140656/ 167/ 30063/ 50/ 6019/ 66/ 964/ schedstat
141/ 167467/ 30067/ 51/ 6033/ 68/ 965/ scsi/
142/ 167476/ 30075/ 51261/ 604/ 69/ 968/ self@
143/ 168/ 30076/ 52/ 6051/ 70/ 969/ slabinfo
143773/ 169056/ 30082/ 53/ 6052/ 71/ 9692/ softirqs
144/ 169087/ 307/ 54/ 6053/ 72/ 975/ stat
145382/ 169094/ 308/ 541/ 6054/ 74/ 9758/ swaps
145383/ 17/ 309/ 56/ 6055/ 748/ 9761/ sys/
145385/ 170640/ 310/ 5692/ 6059/ 75/ 9805/ sysrq-trigger
145404/ 171/ 311/ 5696/ 6062/ 751/ 9811/ sysvipc/
145406/ 18/ 312/ 57/ 6063/ 752/ 99415/ thread-self@
145407/ 180/ 314/ 5706/ 6064/ 76/ 997/ timer_list
145434/ 18185/ 315/ 5708/ 6065/ 77/ acpi/ tty/
145445/ 183/ 316/ 5712/ 6066/ 77335/ asound/ uptime
145459/ 198/ 317/ 5717/ 6067/ 7769/ buddyinfo version
145504/ 2/ 32/ 5775/ 6068/ 78/ bus/ version_signature
145522/ 20/ 320/ 5777/ 6069/ 7868/ cgroups vmallocinfo
145537/ 21/ 321/ 5782/ 6070/ 7869/ cmdline vmstat
145544/ 22/ 322/ 5787/ 6071/ 7907/ consoles zoneinfo
145573/ 23/ 323/ 5795/ 6072/ 7989/ cpuinfo
145583/ 24/ 324/ 58/ 6073/ 7992/ crypto
146/ 242/ 325/ 5800/ 6078/ 80/ devices
147147/ 245/ 326/ 5804/ 6080/ 8006/ diskstats
147151/ 246/ 33/ 5812/ 6081/ 81/ dma
The numbers represent a process (PID - Process ID). Each of these numbers is a directory. Within each of these numbered directories are further files that contain information about the running process. For example the bash shell I am currently running has a PID of "169094". We can "cd" to that directory and take a look:
$ echo $$
169094
$ cd /proc/169094
$ ls -F
arch_status environ mountinfo personality statm
attr/ exe@ mounts projid_map status
autogroup fd/ mountstats root@ syscall
auxv fdinfo/ net/ sched task/
cgroup gid_map ns/ schedstat timers
clear_refs io numa_maps sessionid timerslack_ns
cmdline limits oom_adj setgroups uid_map
comm loginuid oom_score smaps wchan
coredump_filter map_files/ oom_score_adj smaps_rollup
cpuset maps pagemap stack
cwd@ mem patch_state stat
Overview of some of the notable entries
cmdline : Contains the command that originally started the process.
cwd : a symbolic link to the current working directory of the process.
lrwxrwxrwx 1 john john 0 May 10 19:53 cwd -> /proc/169094
environ : This file contains variable information relating to the process.
exe : a symbolic link pointing to the original executable file
lrwxrwxrwx 1 john john 0 May 10 19:49 exe -> /bin/bash
fd : Is a directory that contains symbolic links for each open file descriptor:
$ pwd
/proc/169094/fd
$ ls -l
total 0
lrwx------ 1 john john 64 May 10 19:49 0 -> /dev/pts/0
lrwx------ 1 john john 64 May 10 19:49 1 -> /dev/pts/0
lrwx------ 1 john john 64 May 10 19:49 2 -> /dev/pts/0
lrwx------ 1 john john 64 May 10 20:02 255 -> /dev/pts/0
fdinfo : A directory that contains files that relate to each open file descriptor found in "/fd".
maps : A file containing information about mapped files and blocks.
mem : A binary file that represents the processes virtual memory.
root : A symbolic link to the root path as seen by the process.
status
: A file that contains information relating to the process regarding its current run state and memory usage.task : This directory contains links to any tasks that have been started by this process.
Important Directories to know
At times it useful to know where to find information about your system quickly. You may wish to find memory information or information regarding your CPUs present on your system. This information can be found under "/proc". Many utilities and programs will read the information contained in many of these directory structures and report this back to your screen.
Below is a list of some of most useful to know directories:
/proc/fb : List of available frame buffers.
/proc/cpuinfo : Lists information about your systems CPU - Family, vendor information, Model number, Core Speeds and CPU flag information.
/proc/devices : Contains a list of character and block devices.
/proc/diskstats : Lists information relating to Logical Disk Devices.
/proc/filesystems : List of filesystems that are supported by the kernel.
/proc/interrupts : Interrupt information can be found here.
/proc/iomem : Contains a map of the systems memory for each physical device.
/proc/ioports : Contains a list of currently registered port regions used for input or output communication with a device.
/proc/irq : This directory contains directories that correspond to IRQs present on your system. SMP affinity information may be modified here.
/proc/meminfo : Contains kernel memory information.
/proc/modules : Contains currently loaded modules within the kernel. "lsmod" command obtains its information from here.
/proc/mounts : Contains information regarding mounts. Filesystems in use and what mount options are in use are also listed.
/proc/net : Network stack information.
/proc/partitions : A list of the device numbers, their size and their /dev names which the kernel has identified as a partition.
/proc/slabinfo : Contains kernel slab statistics.
/proc/swaps : List of active swap partitions and their size.
/proc/sys : Dynamically configurable kernel options can be found here.
/proc/uptime : The amount of time in seconds the kernel has been running since boot time and spent in idle mode.
/proc/version : Contains kernel information, version number, gcc version number used for building the kernel.
What is sysfs?
Many newer distributions of Linux are using "sysfs" mounted on /sys as a way of exporting information from the kernel to various applications. "sysfs" generally contains nine top level directories:
$ pwd
/sys
drwxr-xr-x 2 root root 0 May 10 19:14 block
drwxr-xr-x 45 root root 0 May 10 19:14 bus
drwxr-xr-x 69 root root 0 May 10 19:14 class
drwxr-xr-x 4 root root 0 May 10 19:14 dev
drwxr-xr-x 19 root root 0 May 10 19:14 devices
drwxr-xr-x 6 root root 0 May 10 19:14 firmware
drwxr-xr-x 9 root root 0 May 10 19:14 fs
drwxr-xr-x 2 root root 0 May 10 19:14 hypervisor
drwxr-xr-x 14 root root 0 May 10 19:14 kernel
drwxr-xr-x 213 root root 0 May 10 19:14 module
drwxr-xr-x 3 root root 0 May 10 19:15 power
Brief explanation of directories within "/sys"
/sys/block : Contains known block devices.
/sys/bus : Contains all registered buses.
/sys/class : Contains Devices.
/sys/device : All devices known by the kernel organized by the bus that they connect to.
/sys/firmware : Contains firmware files for some devices.
/sys/fs : Contains files to control filesystems.
/sys/kernel : Various kernel related files.
/sys/module : Loaded kernel modules. Each module is represented by a directory of the same name.
/sys/power : Various files to handle power state of system.