proc file system in Linux

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 the useful information about the processes that are currently running, it is regarded as control and information centre 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:

directory description
/proc/PID/cmdline Command line arguments.
/proc/PID/cpu Current and last cpu in which it was executed.
/proc/PID/cwd Link to the current working directory.
/proc/PID/environ Values of environment variables.
/proc/PID/exe Link to the executable of this process.
/proc/PID/fd Directory, which contains all file descriptors.
/proc/PID/maps Memory maps to executables and library files.
/proc/PID/mem Memory held by this process.
/proc/PID/root Link to the root directory of this process.
/proc/PID/stat Process status.
/proc/PID/statm Process memory status information.
/proc/PID/status Process status in human readable form.

Some other files in /proc file system are:

file description
/proc/crypto list of available cryptographic modules
/proc/diskstats nformation (including device numbers) for each of the logical disk devices
/proc/filesystems list of the file systems supported by the kernel at the time of listing
/proc/kmsg holding messages output by the kernel
/proc/meminfo summary of how the kernel is managing its memory.
/proc/scsi information about any devices connected via a SCSI or RAID controller
/proc/tty information about the current terminals
/proc/version containing the Linux kernel version, distribution number, gcc version number (used to build the kernel) and any other pertinent information relating to the version of the kernel currently running

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/Procfs
2) /proc



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.