Proc file system in Linux

Robert Darius Mandru
DigitalGate Amg Blog
6 min readJul 31, 2024
https://digitalgateamg.com/blog/2022/06/17/proc-file-system-in-linux-2/

The Proc file system is one of the most used simulated file systems in the Linux operating system. When the system reboots, this file system is created on the fly, and it is subsequently removed when the system suspends. It acts as the kernel’s controller and knowledge center, storing vital information about current operations. The proc file system is widely used to communicate between the kernel and Linux userspace.
In this article we will discuss how to use the proc file system in Ubuntu linux.

Information about the System

Investigating the properties of the /proc pseudo-filesystem and its ability to provide information about the running Linux system, examining the /proc structure, and discovering various information about the kernel and processes running on the system, are all part of the process of gathering information about the system.

Listing of directory content /proc

As a first step, we must be in the root directory (‘/’), from there we enter the /proc directory where we use the specific command to list the contents of a directory for additional information.

cd /proc
ls -l

Also, to view only the directories in /proc we use:

ls –d */

You’ll see that each PID of a process has its own directory if you list the directories.
Now let’s look for a specific process with a specific PID, you can retrieve the PID of any process currently running via the ps command.

ps –aux

We can also make selections for our processes using the command below.

ps -eo user,pid,ppid,cmd,%mem,%cpu --sort=-%mem

As you can see, after executing this command, we will only see the columns that were given in the command, such as user, pid, ppid, cmd, memory utilized by each process, and cpu, in the list of our processes.

Now let’s see more details about a process, let’s take as an example the process with PID = 17.

cd 17
ls –l

Under Linux, the /proc directory contains a directory for each running process, including kernel processes, in directories labeled /proc/PID.

Here are the directories that are present:

Additionally, as you can see in /proc, we may have files in addition to directories.

These files are:

Viewing the contents of files in the /proc directory

Let’s go further on the example with process PID = 17 and see the content of the status file in it with a specific command.

cat /proc/17/status

Content of status files:

Detailed network information in the /net directory of /proc

Now let’s see the contents of the net file from the PID = 17 processes exemplified above:

Some information about the network in the process directory analysis:

Viewing a network-specific file, in this case, the file dev:

Detailed information about SCSI

In /proc/scsi, if your system has a SCSI host adapter, you’ll see a subfolder named after the adapter’s driver. In /proc/scsi, you’ll find a list of all known SCSI devices.

/proc/tty contains TTY information

The /proc/tty directory contains information about the available and currently utilized ttys. There are entries for drivers and line disciplines in this directory, and we can view the material in more detail below.

  • Idiscs: all disciplines that have been registered
  • Drivers: a list of drivers and how they’re used
  • Driver/serial: Single tty line utilization statistics and status

/proc/stat contains a variety of kernel statistics

The /proc/stat file contains many bits of information concerning kernel activity. All of the figures in this file are averages from when the system was originally started. Simply cat the file for a quick look:

The numbers in all subsequent “cpuN” lines are added together in the initial “cpu” line. These figures show how much time the CPU has spent doing various types of tasks. Units of time are in USER HZ (typically hundredths of a second). From left to right, these are the meanings of the columns:

  • For each of the potential system interrupts, the “intr” line provides counts of interrupts handled since startup time. Each succeeding column is the total for that specific numbered interrupt, whereas the first column represents the total for all interrupts handled, including unnumbered architecture specific interrupts. Unnumbered interruptions are merely added to the total and not displayed.
  • The total number of context switches across all CPUs is displayed on the “ctxt” line.
  • According to seconds since the Unix epoch, the “btime” line indicates the time the system booted.
  • The number of processes and threads created, including but not limited to those produced by calls to the fork() and clone() system functions, are listed in the “processes” line.
  • The number of active or available threads is displayed in the “procs running” line (i.e., the total number of runnable threads).
  • The number of processes that are currently blocked while awaiting I/O completion is displayed on the “procs blocked” line.
  • For each of the potential system softirqs, the “softirq” line provides counts of softirqs that have been handled since boot time. The total for all softirqs serviced appears in the first column, and the total for each individual softirq appears in the following columns.

About parameters per process

Display of IO fields:

sudo cat /proc/17/io

Display of IO fields:

Cat /proc/17/mountinfo

Summary

The /proc file system stores data about the current operating system. It not only gives you access to process data but also lets you read files in the hierarchy to get the kernel status.
The /proc directory layout represents the many sorts of data and makes it straightforward, although not obvious, to find specific data.
Certain parts of kernel behavior can be changed at runtime without recompiling or rebooting the system. The /proc/sys tree contains files that may be read as well as edited. You can change the kernel’s default settings by using the echo command to write values to these files.

References

Please check the following for further information on utilizing the proc Filesystem in Linux:

--

--