Skip to content
Related Articles

Related Articles

proc file system in Linux
  • Difficulty Level : Easy
  • Last Updated : 31 Jan, 2019
GeeksforGeeks - Summer Carnival Banner

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:

directorydescription
/proc/PID/cmdlineCommand line arguments.
/proc/PID/cpuCurrent and last cpu in which it was executed.
/proc/PID/cwdLink to the current working directory.
/proc/PID/environValues of environment variables.
/proc/PID/exeLink to the executable of this process.
/proc/PID/fdDirectory, which contains all file descriptors.
/proc/PID/mapsMemory maps to executables and library files.
/proc/PID/memMemory held by this process.
/proc/PID/rootLink to the root directory of this process.
/proc/PID/statProcess status.
/proc/PID/statmProcess memory status information.
/proc/PID/statusProcess status in human readable form.

Some other files in /proc file system are:

filedescription
/proc/cryptolist of available cryptographic modules
/proc/diskstatsnformation (including device numbers) for each of the logical disk devices
/proc/filesystemslist of the file systems supported by the kernel at the time of listing
/proc/kmsgholding messages output by the kernel
/proc/meminfosummary of how the kernel is managing its memory.
/proc/scsiinformation about any devices connected via a SCSI or RAID controller
/proc/ttyinformation about the current terminals
/proc/versioncontaining 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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :