proc file system in Linux

03 Dec, 2021
Proc file system (procfs) is virtual file system created on fly when system boots and is dissolved at time of system shut down.
It contains useful information about the processes that are currently running, it is regarded as control and information center for kernel.
The proc file system also provides communication medium between kernel space and user space.
Below is snapshot of /proc from my PC.
ls -l /proc

total 0
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 10
dr-xr-xr-x  9 avahi        avahi          0 Mar 31 21:34 1034
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1036
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1039
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1041
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1043
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1044
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1048
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 105
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1078
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 11
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1121
dr-xr-xr-x  9 lp           lp             0 Mar 31 21:34 1146
dr-xr-xr-x  9 postgres     postgres       0 Mar 31 21:34 1149
dr-xr-xr-x  9 mysql        mysql          0 Mar 31 21:34 1169
dr-xr-xr-x  9 postgres     postgres       0 Mar 31 21:34 1180
dr-xr-xr-x  9 postgres     postgres       0 Mar 31 21:34 1181
dr-xr-xr-x  9 postgres     postgres       0 Mar 31 21:34 1182
dr-xr-xr-x  9 postgres     postgres       0 Mar 31 21:34 1183
dr-xr-xr-x  9 postgres     postgres       0 Mar 31 21:34 1184
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 1186
dr-xr-xr-x  9 root         root           0 Mar 31 21:34 12

...

If you list the directories, you will find that for each PID of a process there is dedicated directory.You can check directories only on terminal using
ls -l /proc | grep '^d'

Now let’s check for particular process of assigned PID, you can get the PID of any running process from ps command
ps -aux

Output:
ps -aux command output
Now check the highlighted process with PID=7494, you can check that there is entry for this process in /proc file system.
ls -ltr /proc/7494

Output:
total 0
-rw-r--r--  1 mandeep mandeep 0 Apr  1 01:14 oom_score_adj
dr-xr-xr-x 13 mandeep mandeep 0 Apr  1 01:14 task
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:16 status
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:16 stat
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:16 cmdline
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:17 wchan
-rw-r--r--  1 mandeep mandeep 0 Apr  1 01:17 uid_map
-rw-rw-rw-  1 mandeep mandeep 0 Apr  1 01:17 timerslack_ns
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:17 timers
-r--------  1 mandeep mandeep 0 Apr  1 01:17 syscall
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:17 statm
-r--------  1 mandeep mandeep 0 Apr  1 01:17 stack
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:17 smaps
-rw-r--r--  1 mandeep mandeep 0 Apr  1 01:17 setgroups
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:17 sessionid
-r--r--r--  1 mandeep mandeep 0 Apr  1 01:17 schedstat
-rw-r--r--  1 mandeep mandeep 0 Apr  1 01:17 sched
lrwxrwxrwx  1 mandeep mandeep 0 Apr  1 01:17 root -> /proc/2341/fdinfo
-rw-r--r--  1 mandeep mandeep 0 Apr  1 01:17 projid_map
-r--------  1 mandeep mandeep 0 Apr  1 01:17 personality

...

In linux, /proc includes a directory for each running process, including kernel processes, in directories named /proc/PID, these are the directories present:
Some other files in /proc file system are:
For example, the contents of /proc/crypto are
less /proc/crypto

name         : ccm(aes)
driver       : ccm_base(ctr(aes-aesni), cbcmac(aes-aesni))
module       : ccm
priority     : 300
refcnt       : 2
selftest     : passed
internal     : no
type         : aead
async        : no
blocksize    : 1
ivsize       : 16
maxauthsize  : 16
geniv        : 

name         : ctr(aes)
driver       : ctr(aes-aesni)
module       : kernel
priority     : 300
refcnt       : 3
selftest     : passed
internal     : no
type         : blkcipher
blocksize    : 1
min keysize  : 16
max keysize  : 32
ivsize       : 16
geniv        : chainiv

...

References :1) /wiki/Procfs2) /proc
nnr223442
as5853535
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.