/proc, in short for “process”, is a virtual file-system, that is created every time the system starts up. It contains information related to the ongoing processes, memory management as well as some hardware configurations.
Every Linux has
/proc file-system no matter the type or version. Being a virtual file-system, it can be accessed from any directory in Linux. To get inside the file-system, we run the command:
Table of Contents
- 1 How to visit ‘/proc’ file-system?
- 2 Contents of /proc file-system
- 3 Color scheme
- 4 Numbered Directories
- 5 Memory Statistics
- 6 CPU Information
- 7 Files locked by kernel
- 8 Cryptographic modules
- 9 Supported file-systems
- 10 Other files in ‘/proc’
- 11 Conclusion
How to visit ‘/proc’ file-system?
The first thing we will learn is how to navigate to the /proc file-system.
'cd' refers to as “change directory”, which is used to switch to other directories in Linux.
Contents of /proc file-system
Instead of changing directory, we can instead list all the files of
/proc file-system on the terminal using:
'ls' command is used to list all files and directories present inside the specified location. More on ls here.
'ls' command uses a color scheme for representation of files and directories.
- Blue – The blue part of the output represents sub-directories.
- White – The files that are uncolored are normal files containing data.
- Cyan – The cyan colored files are symbolic links.
As we can see
/proc contains a huge number of files and directories. We will go through some important ones.
Each numbered directory denotes a Process ID. Process ID (PID) is a unique ID given a particular process that is either running or sleeping in the system. Each process directory contains files that store information about the respective process.
It must be noted that each process is crucial for the proper functioning of the system. Therefore, for complete access of each file in process directories, we need root access. It can be achieved by
'sudo -s' or
'sudo su' in Linux. More information on sudo.
Let us look at an example for process with PID = 15.
List of contents
Extracting the contents of the directory numbered 15, can be done by:
To extract information regarding the process 15, we run:
'cat' is Linux tool for concatenating files. Here, we just used it to extract data stored in
'status' file inside
To verify the authenticity of the output, we can always check the process status using the ps command by:
ps -p 15
The above command filters out the process status according to the given PID.
Each file inside
'/proc/15' contains some information related to process
'15'. Some of the files are:
- /proc/15/mem – The memory the process already holds.
- /proc/15/environ – The environment variables set during the initiation of the process.
- /proc/15/cwd – The link to the current working directory (CWD) of the process.
- /proc/15/limits – Stores the values of resource-limits like CPU Time or Memory space.
- /proc/15/fd – The directory which contains file descriptors.
- /proc/15/cmdline – It contains the whole command line for the process.
To learn more about such files inside process-related directories, we can refer the manual pages using
To access details related to CPU dependent items like CPU clock speed, model, etc, ‘/proc/cpuinfo’ can be used:
Files locked by kernel
In a multi-threading environment, locking is the key to solve the simultaneous editing of a file.
'/proc/locks' contains the list of locks that are currently being implemented by the kernel.
Each line contains a single lock. It can be interpreted as:
- 1: – The serial number in the
- POSIX – The type of lock implementation.
- ADVISORY – Prevents an attempt to lock the file again.
- WRITE – The type of lock on the basis of access, either READ or WRITE.
- 2056 – The PID of the process that holds the lock.
- 08:07:5899560 – The identification of the file.
- 0 EOF – The starting and ending point of the locked-region of the file.
'/proc/crypto' contains the list of ciphers that are supported by the kernel crypto API. Its contents look like this:
'/proc/filesystems' contains the list of other file-systems currently supported or mounted by the Linux kernel.
The second column of the output contains the name of the file-systems supported, whereas the first column specifies whether it is currently mounted or not.
The use of
'nodev'means, that the following file-system is not mounted.
Other files in ‘/proc’
Some of the other files containing important information are:
- /proc/interrupts – Contains interrupts for each CPU.
- /proc/ioports – Stores the list of all Input/Output ports in use.
- /proc/diskstats – Displays statistics for each disk device.
- /proc/version – Stores the kernel version.
- /proc/tty – Sub-directory containing files related to terminal drivers.
This article on
proc file-system only touches the surface of the topic. It might be enough for a casual Linux user. In a case, you still have a curiosity about the possibilities of
proc file-system, then you can make use of the man command
Thank you for reading. Feel free to comment below for more queries or criticisms.