Open In App

proc file system in Linux

Last Updated : 08 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Proc file system (procfs) is a virtual file system created on the fly when the system boots and is dissolved at the time of system shutdown. It contains useful information about the processes that are currently running, it is regarded as a control and information center for the kernel. The proc file system also provides a communication medium between kernel space and user space.

To List all the files and directories under the `/proc` directory.

ls -l /proc

This command will list all the files and directories under the `/proc` directory with detailed information like permissions, ownership, size, and time of modifications. This information is useful for understanding the current state of our system and diagnosing problems that are related to the running processes.

If we list the directories, you will find that for each PID of a process, there is a dedicated directory. You can check directories only on the terminal using.

ls -l /proc | grep '^d'

To view the information of a specific process assigned a PID.

For a particular process of assigned PID, you can get the PID of any running process from the ps command.

ps -aux
ps -aux

ps -aux

For Example:

If we want to check information about the process with PID 3151, we can use the following command.

ls -ltr /proc/3151

ls -ltr /proc/3151

To View The status of the process with PID 31154, we can use the following command.

ls -ltr /proc/31154/status
ls -ltr /proc/31154/status

ls -ltr /proc/31154/status

To View The memory usage of the process with PID 1628, we can use the following command.

ls -ltr /proc/1628/statm
ls -ltr /proc/1628/statm

ls -ltr /proc/1628/statm

At this point of time there is no memory page allocated to the process at the time the command was executed.

Directories in `/proc` in Linux.

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 information (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
less /proc/crypto

less /proc/crypto

Frequently Asked Questions

How can we view System Uptime?

We can view System Uptime by reading the contents of the /proc/uptime file.  We can use the following command.

cat /proc/uptime
cat /proc/uptime

cat /proc/uptime

Our output is in the format of uptime in seconds and idle time in seconds.

How can we view system memory information?

We can view system memory by reading the content of the /proc/meminfo file. We can use the following command.

cat /proc/meminfo
cat /proc/meminfo

cat /proc/meminfo

The output will contain information about the total memory available, the amount of memory used, and the amount of memory free.

How can we view system processor information?

We can view system memory by reading the content of the /proc/cpuinfo file. We can use the following command.

/proc/cpuinfo
/proc/cpuinfo

/proc/cpuinfo

The output will contain information about the processor’s name, vendor, clock speed, and cache size.

Conclusion

In this article we have talked about proc file system, in which we have learned that it is a way to access system information and configuration parameters in Linux. We have discussed that by using `ls` command with various options we can list all the files and directories under the `/proc` directories and view specific information about a particular process assigned with PID. We have discussed the use of `/proc`, as we can view system uptime, memory information and processor information. Overall, we can say that all this information provided by the proc file system can help diagnose problems related to running processes, monitor system performance, and tune system parameters to optimize the system resources.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads