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

Specific usage of CSS compound selectors

Intersection Selector The intersection selector i...

How to monitor Linux server status

We deal with Linux servers every day, especially ...

Several ways to encrypt and decrypt MySQL (summary)

Table of contents Written in front Two-way encryp...

A brief introduction to the general process of web front-end web development

I see many novice students doing front-end develop...

MySQL Series Database Design Three Paradigm Tutorial Examples

Table of contents 1. Knowledge description of the...

MySQL statement arrangement and summary introduction

SQL (Structured Query Language) statement, that i...

How to connect to MySQL visualization tool Navicat

After installing Navicat The following error may ...

MySQL 5.7.19 (tar.gz) installation graphic tutorial under Linux

The first tutorial for installing MySQL-5.7.19 ve...

How to configure MGR single master and multiple slaves in MySQL 8.0.15

1. Introduction MySQL Group Replication (MGR for ...

Detailed explanation of Vue's calculated properties

1. What is a calculated attribute? In plain words...

Display ellipsis effect when table cell content exceeds (implementation code)

illustrate In front-end development, you often en...

How to invert the implementation of a Bezier curve in CSS

First, let’s take a look at a CSS carousel animat...

React Hook usage examples (6 common hooks)

1. useState: Let functional components have state...

A thorough analysis of HTML special characters

A Thorough Analysis of HTML (14) Special Characte...