I’d like to share an interesting finding with you today. Perhaps, many of you must be already familiar with it but being a newbie, it really intrigued me.
I have recently enrolled myself in the DevOps Ninja program conducted by my organisation- OpsTree. Everything that I’m learning here is new to me and often amuses me. One day, I was working on an assignment and executed the top command. I left the task as it is and meanwhile started browsing something on the internet. Suddenly a question struck my mind that from where the top command fetches its data ( you can see how I got digressed from my main assignment :p).
So, I started exploring (please make note of top command process ID here- 7564) and utilised lsof command to dig deeper.
$ lsof -p <process id>
Here, I happened to find /proc, went in and found a whole lot of process directories which contained a lot of useful information about system processes and its respective activity history.
The /proc directory is present on all Linux systems, regardless of flavor or architecture. The /proc directory is NOT a real file system but a virtual file system that is created dynamically by Linux to provide access to certain types of hardware information and information about the running processes. It is mapped to /proc and mounted at boot time.
To display information about your CPU, you can use the cat /proc/cpuinfo command:
To display information about the file systems supported by currently running Linux kernel:, you can use the cat /proc/filesystems command:
To display statistics about memory usage on the system, use the cat /proc/meminfo command:
To display the Linux kernel version, distribution number and other kernel-related information, use the cat /proc/version command:
Within /proc’s numbered directories, you will find a few files and links. These directories’ numbers correlate to the PID of the command being run within them.
Let’s check what’s there inside in one of these numbered directories. Here, I chose 2016 and run cat status:
In any numbered directory, you will have a similar file structure. The most important ones, and their descriptions, are as follows:
- cmdline – contains the command that started the process
- environ – contains the names and content of the environment variables for the process
- fd – file descriptors
- limits – contains information about the limits of the process
- mounts – related information
You will also notice a number of links in the numbered directory:
- cwd – a link to the current working directory of the process
- exe – link to the executable of the process
- root – link to the work directory of the process
Just like with the hardware information, you can display the content of these files using the cat command.
Blog Pundit: Kapendra Singh
Opstree is an End to End DevOps solution provider