The basic scripts of / proc directory in linux.

Have you ever wondered how your favorite programs like top, ps, free or KDE System Guard get information about the system, such as running processes, amount of free memory, and CPU usage used… or not? Are you studying operating systems, are exposed to system programming? And you want to write such programs yourself? Then, knowledge of the / proc file system is essential for you to know. This article aims to introduce you to basic information about / proc file system so that you can begin to "DIY" the system by yourself.

1. The / proc file system (proc FS)

Proc is a virtual file system (pseudo file system), a real time file system and resident in memory (memory resident) to keep track of running processes along with the state of the system.
Proc is a virtual file system because it does not actually exist in any storage medium. It exists based on virtual memory and data that is dynamically changing with the behavior of the system. Most data in proc FS is constantly updated to match the current state of the operating system. The contents of proc FS can be read by users with appropriate permissions, some of which can only be read by the owner of the process and root. If you list the root (/) directory, you will see


# ls -al /
drwxr-xr-x 2 root root 4096 Feb 22 2006 mnt
drwxr-xr-x 2 root root 4096 Feb 22 2006 opt
dr-xr-xr-x 144 root root 0 Oct 2 20:00 proc 

The proc directory is always = 0 in size and the last modified time is current.

Some common files in The / proc file system (proc FS)

/ proc / cpuinfo

Processor information, such as processor type, make, model, or performance.

/ proc / devices

List of device drivers configured into the currently running kernel

/ proc / dma

Displays the DMA (Direct Memory Access) channels that are in use at the moment.

/ proc / filesystems

The filesystems is configured at the kernel.

/ proc / interrupts

Shows which interrupts are active.

Interrupts - interrupts are events that stop the current job of the CPU, forcing the CPU to do something and then returning to do the old job.

/ proc / ioports

Information of I / O ports being used at the present time.

/ proc / kmsg

The message generated by the kernel. This message is also passed to the syslog.

/ proc / loadavg

Average load information of the system, in addition to the usual 3 numbers corresponding to the load status of the system in 1, 5 and 15 minutes. There are also 2 numbers.

The number of threads running or waiting / total system thread.

The latest PID process of the system.

/ proc / meminfo

Memory usage information, including ram and swap (virtual ram) information.

/ proc / modules

The kernel modules are loaded at this time.

/ proc / net

Status information about network protocols.

/ proc / self

One symbolic link Go to the directory of the program you are currently watching / Proc. When the two processes use / Proc, they get different links.

/ proc / stat

Statistics vary on the system, such as the number of page errors since the system was started up.

/ proc / uptime

System operation time.

/ proc / version

The version of the kernel.

The folders numbered as 1, 4567, 2385, 112, 40, 41… are the Process IDs (PIDs) of the processes running in the system. Each folder will contain information about that process. You can use the command "ps -ef" to list the running processes and compare with the above folder names to know which directory contains information of which process. If you are using a KDE interface, you can try the keyboard shortcut Ctrl + ESC). Cd into a directory, number 1 for example, and ls out to see if there is anything in it.