Linux kernel device driver proc file system notes

Linux kernel device driver proc file system notes
/*****************
 * proc file system*****************/

(1) Characteristics of the /proc file system and description of /proc files

The /proc file system is a special file system created by software. The kernel uses it to export information to the outside world. The /proc system only exists in memory and does not occupy external memory space.

Each file under /proc is bound to a kernel function, which dynamically generates the file's contents when the user reads the file. You can also modify kernel parameters by writing /proc files

File analysis under the /proc directory /proc/$pid Information directory about process $pid. Each process has a directory under /proc named after its process number. Example: $>strings -f /proc/[0-9]*/cmdline

  • /proc/cmdline command line for kernel startup
  • /proc/cpuinfo Processor information such as type, manufacturer, model, and performance.
  • /proc/devices lists the major numbers of character and block devices, and the device names assigned to those numbers.
  • /proc/dma shows the currently used DMA channels.
  • /proc/filesystems lists the filesystem types available for use, usually those built into the kernel, but new types can be added via modules
  • /proc/interrupts shows the interrupt number used, the interrupt name, and the number of times these interrupts have occurred since the system was started
  • /proc/ioports Currently used I/O ports.
  • /proc/kallsyms Kernel symbol table. After installing a new module, it will be reflected here
  • /proc/kcore System physical memory image. Exactly the same size as physical memory, but not actually occupying that much memory; (Remember: nothing under /proc takes up any disk space unless copied to a file)
  • /proc/kmsg Kernel output messages. Also sent to syslog.
  • /proc/loadavg The average load of the system. The first three are the loads of the past 1 minute, 5 minutes, and 15 minutes, followed by the number of running tasks and the total number of tasks, and finally the process number of the last run.
  • /proc/meminfo Memory usage information, including physical memory and swap.
  • /proc/modules Which core modules are currently loaded.
  • /proc/partitions The partition information of the hard disk currently mounted by the system
  • /proc/pci system pci bus information
  • /proc/net Network protocol status information.
  • /proc/self A symbolic link to the process directory of programs that view /proc. When 2 processes look at /proc, they are different connections. This is mainly convenient for a program to get its own process directory.
  • /proc/slabinfo Allocation information of slab cache in the system
  • /proc/stat Some status information of the system
  • /proc/swaps The swap area information used by the system
  • /proc/sysrq-trigger is used to start the sysRq key $>echo 1 > sysrq-trigger
  • /proc/uptime The length of time the system has been up and idle. For uptime use
  • /proc/version Kernel version

(2) Implement a /proc file yourself

The header file <linux/proc_fs.h> needs to be included, and the function is defined in /fs/proc/generic.c

a. Create a file under /proc

Call create_proc_read_entry to create a new file under /proc

struct proc_dir_entry *create_proc_read_entry(
    const char *name,
    mode_t mode, 
    struct proc_dir_entry *base,
    read_proc_t *read_proc, 
    void * data)

b. Uninstall files under /proc

Use remove_proc_entry to uninstall proc files

void remove_proc_entry(
    const char *name, 
    struct proc_dir_entry *parent);

c. Define a function that returns data

When the process reads the /proc file, the kernel allocates a memory page (i.e. a memory block of PAGE_SIZE bytes), and the driver returns the data to be written to the user space through this memory page.

typedef int (read_proc_t)(char *page, char **start, off_t off,
int count, int *eof, void *data);

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Linux kernel device driver memory management notes
  • Linux kernel device driver kernel time management notes
  • Linux kernel device driver character device driver notes
  • Linux kernel device driver virtual file system notes
  • Linux kernel device driver kernel debugging technical notes collation
  • Linux kernel device driver kernel linked list usage notes
  • Detailed explanation of Linux camera driver writing
  • Analysis of parameter transfer process of driver module in Linux

<<:  How to call the browser sharing function in Vue

>>:  Detailed explanation of how to quickly operate MySQL database in nodejs environment

Recommend

Floating menu, can achieve up and down scrolling effect

The code can be further streamlined, but due to t...

MySQL tutorial DML data manipulation language example detailed explanation

Table of contents 1. Data Manipulation Language (...

A brief summary of all encapsulation methods in Vue

Table of contents 1. Encapsulation API 2. Registe...

IE8 Developer Tools Menu Explanation

<br />This article has briefly explained the...

Tutorial on installing mysql5.7.23 on Ubuntu 18.04

This article shares with you the specific method ...

Solution to the failure of entering the container due to full docker space

Since the problem occurred rather suddenly and th...

Compatibility with the inline-block property

<br />A year ago, there were no articles abo...

jQuery achieves seamless scrolling of tables

This article example shares the specific code of ...

How to implement Vue binding class and binding inline style

Table of contents Binding Class Binding inline st...

Linux touch command usage examples

Detailed explanation of linux touch command: 1. C...

How to install Nginx in Docker

Install Nginx on Docker Nginx is a high-performan...

Write a publish-subscribe model with JS

Table of contents 1. Scene introduction 2 Code Op...