How to Use procfs to Get System Related Information in Linux

If you look at the Linux filesystem, you may have noticed a /proc directory with many weird numbers and other files inside it. What does this directory do? It actually contains a lot of useful information associated with your Linux system and the running processes.

This article will discuss the proc filesystem in detail, along with a brief guide on how to get system-related information using procfs.

What Is the proc Filesystem?

The proc filesystem (procfs) is an idea borrowed from the Plan 9 research system from Bell Labs, a research successor to the original Unix system developed there.

The filesystem extends the original concept of having “everything as a file,” including hardware devices, to its logical conclusion by representing every running process on the system as a hierarchy of files that you can examine with standard tools.

The most useful file in the proc hierarchy for system information is the cpuinfo file. To view it, type:

cat /proc/cpuinfo

Depending on how many CPU cores your machine has, this file might contain a lot of information. Therefore, you might want to substitute cat for Most, which is a Linux pager.

Other useful files in the /proc directory are meminfo, which shows details associated with your system memory, and the mounts file, which provides information on the mounted filesystem. You can easily examine these files with standard Linux text processing tools.

Related: Best Command Line Utilities for Viewing File Content in Linux

In the proc filesystem, all the running processes have their own directory, which is their process ID number, or PID. For example, process 1, the init process that starts all other processes on the Linux system at boot time, has its own directory with the same number, /proc/1.

While finding the process you want to investigate, you’ll use the ps command, top, htop, or other Linux commands to list the PID of that particular process. When you’ve found the process ID, navigate to that directory under /proc.

Inside the process directory, you’ll find several files that contain information on different facets of the process. For example, exe is a symbolic link to the executable that started the process, environ lists environment variables, and cmdline shows any command-line arguments the process was launched with. The status file lists a lot of this information in a more “human-readable” format.

Related: What Is a Process in Linux?

Get System Information Using procfs

The proc filesystem shows that just about everything is a file in Linux, even things you wouldn’t expect. Even inside the root folder, you’ll find a lot of files, each of them containing information about different components of the system.

Linux, with its unique commands and countless distros, might seem a mysterious operating system to beginners at first, but everything is in its right place.

Source: makeuseof.com

Related posts

Connections #329: Today’s Answer and Clues (Sunday, May 5, 2024)

PC Fans Running at Full Throttle? 6 Fixes

The 5 Best Free Driver Updaters for Windows