[Linux] proc file system

[Linux] proc file system

foreword

1. Introduction to proc file system

1.1 What is the proc file system?

1.2 The role and characteristics of the proc file system

1.3 Information provided by the proc file system

2. Detailed description of commonly used nodes in the proc file system

2.1 /proc/cpuinfo

2.2 /proc/meminfo

2.3 /proc/kallsyms

2.4 /proc/interrupts

2.5 /proc/loadavg

3. Summary


Foreword

The important link: keep moving forward with problems

In the Linux system, there are some special file systems, which are used to perform unified operations on the file interface to complete various functions, and the proc file system is one of them.

  1. proc file system
  2. The role and characteristics of the proc file system
  3. What information can the proc file system provide
  4. Common usage of proc file system

In the course of learning Linux notes teacher, the teacher’s lectures are concise and in-depth, but some knowledge background is needed to get started. Here I have expanded and summarized.

Reference articles and videos: https://xuesong.blog.csdn.net/article/details/109522945

https://live.csdn.net/v/263371?spm=1001.2014.3001.5501

1. Introduction to proc file system

1.1 What is the proc file system?

The /proc directory on the Linux system is a file system, namely the proc file system.

/ Unlike other common file systems, /proc is a virtual file system that does not contain any files on disk, but files and directories dynamically generated by the kernel at runtime.

In Linux, there is a special kind of pseudo-file system, which performs unified operations on file interfaces to complete various functions, such as ptyfs, devfs, sysfs, and procfs. And procfs is one of the most widely used pseudo file systems.

The mount point of the proc file system is /proc, which was originally designed to provide information when the process is running, such as the running status of the process, the files currently opened by the process, the created sockets, and the arrangement of virtual memory. The origin of its name (Process Data Filesystem). Later, a lot of system-level kernel information was also added, such as interrupt information, device mapping information, memory status and so on.

Overall, the /proc filesystem provides system administrators and developers with a convenient way to query and debug the status and performance of the system.

1.2 The functions and characteristics of the proc file system

The proc file system provides some information about various subsystems in the kernel, which makes it possible to simply use cat and echo commands in user space, or read and write system calls to obtain information about each subsystem of the kernel, Such as CPU model and parameters, memory usage, available timing hardware and detailed parameters, connected external devices and mapping addresses, etc., you can also dynamically modify kernel parameters while the system is running without recompiling the kernel source code.

What are the characteristics of the proc file system?

  • Readability: The information of the proc file system is presented in text format, which makes it easy to read and parse.
  • System level: The proc file system provides access to kernel and system level information such as running processes in the system, memory usage, CPU information, hardware configuration, and more.
  • Can be used for diagnostics and debugging: The proc file system provides real-time access to system state and process information, which makes it very useful for diagnosing and debugging system problems.
  • Stability and maintainability: When it is necessary to modify various parameters and configuration information of the system, we can manage it through the proc file system without writing a special kernel module.

1.3 Information provided by the proc file system

File Introduction
/proc/cpuinfo This file contains detailed information about the CPU, including manufacturer, model, frequency, cache etc.
/proc/meminfo This file contains detailed information about memory, including available memory, cache size, swap partition, etc.
/proc /loadavg This file contains the system’s load average, which represents the average number of processes running on the system and the number of processes waiting for CPU.
/proc/kallsyms The The file is a symbol table that contains the addresses in memory of all global variables and functions of the kernel.
/proc/interrupts The The file contains system-recorded counts of the various types of interrupts processed on each CPU.
/proc/version This The file contains the version information of the system, including kernel version, GCC version and other information.
/proc/net/tcp This file contains information about the TCP connection, including local address, remote address, status and other information.
/proc/net/udp This file contains information about UDP connections, including local address, remote address, status, etc.
/proc/ sys/kernel/hostname This file contains the hostname of the system
/proc/sys/kernel/pid_max This file contains the maximum process ID allowed by the system
/proc/sys/fs/file-nr This file contains statistics about open files, including the number of currently open files, the number of allocated file handles, and the largest file handle

2. Detailed description of commonly used nodes in proc file system

2.1 /proc/cpuinfo

This file contains the parameter information of the current system CPU, including the number of CPU cores, the operating frequency of each core, cache size, word width address line length, etc. For example, on my personal computer, some of the information displayed by cat /proc/cpuinfo is as follows:

2.2 /proc/meminfo

This file shows the current memory status information in the system, such as total physical memory capacity, used memory, free memory, shared memory, swap memory size, and so on.

In daily development work, developers usually prefer to view the current memory usage of the system through the output of the top command, because most of the time, it is enough to only care about the total amount of memory and the current usage.

However, in some special cases, you still need to refer to the more detailed memory status information provided in this file, such as slab memory usage (recording how to divide and allocate memory for small storage areas in a page frame), reclaimable memory The amount (SReclaimable), the size of the kernel stack space (Kernel Stack), the total amount of heap memory allocated using malloc, and the total amount of memory mapped using mmap, and so on.

2.3 /proc/kallsyms

This file is a symbol table that contains the addresses in memory of all global variables and functions of the kernel.

This is a file added to help kernel developers debug the kernel. In the Opps information generated when the Linux system crashes, the function name displayed in the function call stack is generated with the help of this file.

2.4 /proc/interrupts

This file contains system-recorded counts of various types of interrupts processed on each CPU.

In Linux, if there is no special handling, usually all interrupts will be handed over to the first core of the CPU (CPUO) for processing. There is a utility called rqbalance that can help the system distribute interrupts to different CPUs to achieve load balancing, which has a significant effect on the performance improvement and energy consumption control of multi-core processors.

Most of the current Linux distributions will start this service by default on multi-core processors, but just in case, readers can confirm whether the service is enabled on their own systems, and determine the interruption by checking the proc/interrupts file Is it evenly distributed to different CPUs.

2.5 /proc/loadavg

This file shows the average load of the system over time, a real output would look like this:

The specific meaning of the above information is as follows:
1. Average system load over the past minute
2. Average system load over the past five minutes
3. System load average for the past fifteen minutes
4. The number of tasks in the running queue at the sampling time/the total number of active tasks in the system
5. The thread ID that occupies the largest at the time of sampling

The first three values in the output of this file are often used to observe trends in system load. If the previous value is smaller than the latter value, it means that the system load is decreasing; otherwise, it means that the system load starts to show an upward trend.

3. Summary

The existence of a special file system makes Linux have an extremely simple interface for viewing and modifying kernel data, while maintaining powerful and flexible functions.

The proc file system makes the system easy to debug and maintain, and improves the stability and maintainability of the system.

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. CS introductory skill tree Introduction to LinuxFirst acquaintance with Linux31509 People are studying systematically