5

How to Use procfs to Get System Related Information in Linux

 3 years ago
source link: https://www.makeuseof.com/use-procfs-get-system-information-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.

Linux /proc directory listing

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

Get Process-Related Information Using procfs

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.

Process status file

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.

About The Author

6053bdfb33ee5-David_Delony_Headshot.jpg?fit=crop&w=100&h=100

David Delony (35 Articles Published)

David is a freelance writer based in the Pacific Northwest, but originally hailing from the Bay Area. He has been a technology enthusiast since childhood. David's interests include reading, watching quality TV shows and movies, retro gaming, and record collecting.

More From David Delony

Subscribe To Our Newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK