Exploring /proc File System in Linux

Today, we are going to take a look inside the /proc directory and develop a familiarity with it. The /proc directory is present on all Linux systems, regardless of flavor or architecture.

One misconception that we have to immediately clear up is that the /proc directory is NOT a real File System, in the sense of the term. It is a Virtual File System. Contained within the procfs are information about processes and other system information. It is mapped to /proc and mounted at boot time.

Linux proc file system

Exploring /proc File System

First, lets get into the /proc directory and have a look around:

# cd /proc

The first thing that you will notice is that there are some familiar sounding files, and then a whole bunch of numbered directories. The numbered directories represent processes, better known as PIDs, and within them, a command that occupies them. The files contain system information such as memory (meminfo), CPU information (cpuinfo), and available filesystems.

Read Also:  Linux Free Command to Check Physical Memory and Swap Memory

Let’s take a look at one of the files first:

# cat /proc/meminfo
Sample Output

which returns something similar to this:

MemTotal:         604340 kB
MemFree:           54240 kB
Buffers:           18700 kB
Cached:           369020 kB
SwapCached:            0 kB
Active:           312556 kB
Inactive:         164856 kB
Active(anon):      89744 kB
Inactive(anon):      360 kB
Active(file):     222812 kB
Inactive(file):   164496 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         89724 kB
Mapped:            18012 kB
Shmem:               412 kB
Slab:              50104 kB
SReclaimable:      40224 kB
...

As you can see, /proc/meminfo contains a bunch of information about your system’s memory, including the total amount available (in kb) and the amount free on the top two lines.

Running the cat command on any of the files in /proc will output their contents. Information about any files is available in the man page by running:

# man 5 /proc/<filename>

I will give you quick rundown on /proc’s files:

  1. /proc/cmdline – Kernel command line information.
  2. /proc/console – Information about current consoles including tty.
  3. /proc/devices – Device drivers currently configured for the running kernel.
  4. /proc/dma – Info about current DMA channels.
  5. /proc/fb – Framebuffer devices.
  6. /proc/filesystems – Current filesystems supported by the kernel.
  7. /proc/iomem – Current system memory map for devices.
  8. /proc/ioports – Registered port regions for input output communication with device.
  9. /proc/loadavg – System load average.
  10. /proc/locks – Files currently locked by kernel.
  11. /proc/meminfo – Info about system memory (see above example).
  12. /proc/misc – Miscellaneous drivers registered for miscellaneous major device.
  13. /proc/modules – Currently loaded kernel modules.
  14. /proc/mounts – List of all mounts in use by system.
  15. /proc/partitions – Detailed info about partitions available to the system.
  16. /proc/pci – Information about every PCI device.
  17. /proc/stat – Record or various statistics kept from last reboot.
  18. /proc/swap – Information about swap space.
  19. /proc/uptime – Uptime information (in seconds).
  20. /proc/version – Kernel version, gcc version, and Linux distribution installed.

Within /proc’s numbered directories you will find a few files and links. Remember that these directories’ numbers correlate to the PID of the command being run within them. Let’s use an example. On my system, there is a folder name /proc/12:

# cd /proc/12
# ls
Sample Output
attr        coredump_filter  io         mounts      oom_score_adj  smaps    wchan
autogroup   cpuset           latency    mountstats  pagemap        stack
auxv        cwd              limits     net         personality    stat
cgroup      environ          loginuid   ns          root           statm
clear_refs  exe              maps       numa_maps   sched          status
cmdline     fd               mem        oom_adj     schedstat      syscall
comm        fdinfo           mountinfo  oom_score   sessionid      task

If I run:

# cat /proc/12/status

I get the following:

Name:	xenwatch
State:	S (sleeping)
Tgid:	12
Pid:	12
PPid:	2
TracerPid:	0
Uid:	0	0	0	0
Gid:	0	0	0	0
FDSize:	64
Groups:
Threads:	1
SigQ:	1/4592
SigPnd:	0000000000000000
ShdPnd:	0000000000000000
SigBlk:	0000000000000000
SigIgn:	ffffffffffffffff
SigCgt:	0000000000000000
CapInh:	0000000000000000
CapPrm:	ffffffffffffffff
CapEff:	ffffffffffffffff
CapBnd:	ffffffffffffffff
Cpus_allowed:	1
Cpus_allowed_list:	0
Mems_allowed:	00000000,00000001
Mems_allowed_list:	0
voluntary_ctxt_switches:	84
nonvoluntary_ctxt_switches:	0

So, what does this mean? Well, the important part is at the top. We can see from the status file that this process belongs to xenwatch. Its current state is sleeping, and its process ID is 12, obviously. We also can see who is running this, as UID and GID are 0, indicating that this process belongs to the root user.

In any numbered directory, you will have a similar file structure. The most important ones, and their descriptions, are as follows:

  1. cmdline – command line of the process
  2. environ – environmental variables
  3. fd – file descriptors
  4. limits – contains information about the limits of the process
  5. mounts – related information

You will also notice a number of links in the numbered directory:

  1. cwd – a link to the current working directory of the process
  2. exe – link to the executable of the process
  3. root – link to the work directory of the process

This should get you started with familiarizing yourself with the /proc directory. It should also provide insight to how a number of commands obtain their info, such as uptime, lsof, mount, and ps, just to name a few.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Rob Krul

Rob is an avid user of Linux and Open Source Software, with over 15 years experience in the tech geek universe. Aside from experimenting with the many flavors of Linux, he enjoys working with BSDs, Solaris, and OS X. He currently works as an Independent IT Contractor.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

5 Responses

  1. situn says:

    /proc directory have 0kb files but there are some files which have some size what are those files?

  2. Paul R says:

    Minor issue – it’s /proc/consoles (with an s at the end)

    Also you might want to add mention of /proc/self and why this happens:

    [email protected]:~$ cd /proc/self
    [email protected]:/proc/self$ readlink -e .
    /proc/7803
    [email protected]:/proc/self$ readlink -e /proc/self
    /proc/11257

  3. Ricky Tan says:

    Thanks for the info sir.. very much appreciated

  4. Rob Krul says:

    Depending on what type of hardware you have, you can get a lot of information in some of the /proc files. Since you were asking specifically about your video card, you can run:

    $ cat /proc/pci

    If it is using an ISA slot, you can run the following:

    $ cat /proc/isapnp

    If you are looking for your hard drive info:

    cat /proc/scsi/scsi

    The man page of /proc/ will give you plenty of info about any file in the /proc directory.

    Of course, there are easier ways to obtain this information, and utilities that are much more script-friendly. lshw is the first:

    $ lshw -class disk

    There is also hwinfo:

    $ hwinfo –disk

    And the very script-friendly lsblk:

    $ lsblk -io KNAME,TYPE,SIZE,MODEL

    All three of those utilities are available through apt or yum.

  5. Ricky Tan says:

    Hi

    Just a question, what file in /proc will I know the brand of my hard disk? memory video card? is it all located in /proc?

    thanks

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.