Using the /proc Filesystem to Examine Your Linux Inner Working

Quick – answer me this: How much swap space is in use on your system right now? How big is the cache on your CPU? What kernel modules are currently loaded? How many total drives and partitions are you running? If you’re running Linux, all these questions (and a whole lot more) can be answered one easy way: take a look in /proc. It’s a goldmine of system information, just waiting to be retrieved by users, administrators, and scripts. In this guide we’ll take a trip through /proc to see just what valuable system information you’ve been missing out on.

About /proc

Probably the most important thing to understand about /proc is that it’s not a normal directory with normal files. It’s more like a viewscreen into the system internals. Files in this directory are not read and saved to the hard drive like your average document or MP3, they’re generated by the Linux kernel on the fly. Accessing the file /proc/meminfo will likely give you different results each time, because memory usage is nearly always fluctuating.

By putting this kind of system information into a virtual filesystem like proc, the developers adhere to the UNIX philosophy “everything is a file”. They do this so that it can be easily read by any person or software as easily as a normal text file, no special libraries or languages necessary. For us, this means that up-to-date system information is always easily available.

Note: The files mentioned here should all open cleanly in any text editor of your choice. The examples here are showing the contents using the standard cat command from within a terminal.

/proc/cpuinfo

If you’ve spent any time at all in proc, there’s a good chance you’re familiar with this file. Displaying the contents of cpuinfo will give you a detailed picture of exactly what CPU you have and what features it supports.

proc-cpuinfo

/proc/meminfo

The other most well known file in proc, meminfo is an extremely handy file to keep around. It shows you information about memory and swap usage, and is one way that scripts and programs can find out what’s available.

proc-meminfo

/proc/cmdline

This file shows the options that were used to start the kernel. This can be handy when troubleshooting boot problems, or if you need to verify exactly which kernel file was used for boot.

proc-cmdline

/proc/filesystems

A lesser known but still useful file is filesystems. From here you can read the (somewhat extensive) list of filesystems currently supported by your kernel. Not all of these are the type of filesystems you’d use to store your data, some are like proc itself and have special-purpose uses.

proc-filesystem

/proc/PID

In this case, PID is the process ID of a running program. Each process has a unique number that the system uses to identify that particular instance of that particular program. For example, when you run the program top from the command line, you see a list of running processes and their PIDs. Each process has its own subdirectory in proc, which you can browse for information about that particular process.

proc-pid

/proc/modules

One of the most vital of the files in proc, modules contains a complete list of the currently active kernel modules. If you’ve ever had to work through video driver issues, you likely know how useful this can be. While likely not something you’d use every day, this file can be a lifesaver for troubleshooting.

proc-modules

/proc/mounts

You can quickly and easily check all your mounted devices by opening the mounts file. Once again, many of the items here are not necessarily mounts points that a user need be aware of. Most of the sections relevant to you will be found toward the bottom.

proc-mounts

Conclusion

There’s certainly more to proc than can be covered here, so I’d greatly encourage anyone reading this to do some poking around in proc to find the bits of information that could be really useful to you. While many of the files you’ll find there are intended to be used by the OS itself, they can all provide a valuable look into Linux’s operations.

Do you like what you read here?

Receive the latest update in your inbox.

Or connect with us: