Getting started with embedded linux 3-7proc file system

overview

proc - process information pseudo-filesystem (process information virtual file system)

The proc file system is a virtual file system used to provide an interface to kernel data structures. Usually it is mounted in the /proc directory. Generally, the system will automatically mount this file system. Of course, you can also use the following command to mount it manually:

mount -t proc proc /proc # 可以看到proc文件系统的类型也为proc

Most of the files in this file system are read-only, but there are some writable files, and modifying these files can modify some kernel runtime variables.

From the name, this file system was only used to provide process-related information at the beginning, and later it was used to store other system-related information as it developed.

Files and Subdirectories

The files and subdirectories under the /proc directory are roughly divided into the following categories:

  1. /proc/[pid] subdirectory
    This type of subdirectory is named after the pid of the corresponding process, and the files and subdirectories under it contain the running information of the corresponding process. For a process that uses multi-threading, there will generally be a task subdirectory under it, and the files in the subdirectory named after tid in the task subdirectory contain relevant information of each thread. These subdirectories are visible when traversing the /proc directory using the getdents() function, and can also be viewed using the ls command.

  2. /proc/[tid] subdirectory
    is the same as the subdirectory named by each tid under /proc/[pid]/task/, but for the getdents() function and ls command, these directories are not visible.

  3. /proc/self soft link
    A magical link, when a process accesses this directory, it is equivalent to accessing the /proc/[pid] directory corresponding to its own pid

  4. The /proc/thread-self soft link
    is also a magical link. When a thread accesses this directory, it is equivalent to accessing the /proc/self/task/[tid] directory corresponding to its tid

  5. /proc/[az]* Other files and subdirectories
    Commonly used files are as follows:

    file name use
    cmdline Record kernel boot parameters
    cmdline Record kernel boot parameters
    cpuinfo CPU related information
    iomem Memory usage of IO devices
    interrupts Display occupied interrupt and occupant information
    ioports IO port usage
    girl System physical memory image, unreadable
    loadavg System load average
    meminfo Physical memory and swap partition usage
    modules List of loaded modules
    mounts Information about mounted filesystems
    partitions Partition table recognized by the system
    swaps Swap partition utilization
    version Kernel version information
    uptime system uptime

Instructions

The program can directly use the standard IO or the file read and write functions of the C library to access the information in it, and use cat in the shell to directly print the file content.

A picture to get /proc

A picture clearly shows the ins and outs of the /proc directory:

Original URL: SecurityZines : Understand log4j in and out in flyer

mmexport1651761193108

Guess you like

Origin blog.csdn.net/lczdk/article/details/124599639