×

Search anything:

proc file system in Linux

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

The proc file system is a virtual file system generated on the fly when the system starts. In this article, we learn about the files and directories making up this file system.

Table of contents.

  1. Introduction.
  2. The file structure.
  3. Data.
  4. Summary.
  5. References.

Introduction.

The proc file system is a virtual file system that is generated on the fly when the system boots up and destroyed when the system shuts down.

Files in this file system are not actual files, rather are magic objects behaving like files that provide access to parameters, data structures, and other kernel information and statistics.

For example:

$ ll /proc/version

This is one of the files, notice the size is zero, this is because it is generated by the kernel, also notice the modification date, the time stamp is similar to the time the system was booted up.

The above file holds contents involving the version number of the kernel, the same information obtained by executing the uname command:

$ uname -a

To read the file we concatenate it:

$ cat /proc/version

proc1

The file structure.

Let's now list the contents of the /proc directory:

$ ls /proc

proc2

From the output, we can see three distinct colors, blue, white, and cyan/light blue.

  • Blue represents subdirectories. Some are numbered which is a representation of a specific process.
  • White represents normal files containing data e.g, memory statistics, cpu information etc.
  • Cyan files are symbolic links.

As we can also see some of the blue subdirectories are numbered. These numbers represent process IDs PIDS. Each directory will store information related to the process whose ID corresponds to the file name.

That is, a process will PID ** will have its data in subdirectory **.

Also notice that most of these subdirectories have similar files, such as mem for the memory the process uses, status - the current status of a process, CWD - the current working directory, syscall - the process system calls, limits - the resource limits of the process, etc. Thes files hold information about the process. For example, to get the status of a particular process we concatenate the contents of the status file in the process' subdirectory.

$ cat /proc/1800/status

proc3

In this case, the output will be the status of a process with a PID of 1800 in our example it is a gnome-session process.

We can confirm this by executing the command:

$ ps -p 1800

proc4

To view the memory details of a process we write:

$ cat /proc/[process ID]/mem

Data.

As mentioned earlier the white colored files have data about the kernel.
These are:

$ ls -p /proc/ | grep -v /

proc5

For example to view the system's memory data we write:

$ cat /proc/meminfo

This information is also obtainable using the free command.

$ free

proc6

This goes to say that when we execute Linux commands, they fetch their data from this file system and print it out as output.
For example, the uptime command displays information about the system's uptime in seconds. This command uses data in the /proc/uptime file to calculate its command output:

$ cat /proc/uptime

And now to execute the command itself:

$ uptime

proc7

To print data regarding the CPU we concatenate the cpuinfo file:

$ cat /proc/cpuinfo

proc8

Such information is useful in cases where we have a new system and are curious about the processor. Information such as its model number and name, vendor id, cache size, speed, etc will be displayed.

Another important file is the cmdline file. This file stores the parameters passed to the kernel when it is booted.

$ cat /proc/cmdline

proc9

Other files include:

  • console - stores information about the current kernel consoles.
  • devices - has information about currently configured device drivers.
  • filesystems - file systems supported by the kernel.
  • iomem - information about current system memory map for devices.
  • locks - files locked by the kernel.
  • mounts - data about mounts used by the kernel.
  • pci - data about PCI devices.
  • partitions - data about partitions in the kernel.
  • swap - data regarding swap space.
  • fb - data about frame buffer devices.
  • Just to name a few.

Summary.

Proc files are very useful in cases where we don't want to execute long complex text filtering commands. In such cases, we just read the appropriate file to get the raw information we need.

Also keep in mind that, some of the data in this file system is not as reliable for use in system analysis and so we should keep to commands just in case.

It is also worth noting that, we can change the configuration of the kernel by writing to some of these files.

References.

Advanced Linux Programming - Mark Mitchell. Chapter 7.

proc file system in Linux
Share this