Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of proc File system of Linux Kernel device driver

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "Linux kernel device driver proc file system example analysis", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "Linux kernel device driver proc file system example analysis" this article.

/ * * proc file system * /

(1) Features of / proc file system and description of / proc file

The / proc file system is a special, software-created file system that the kernel uses to export information to the outside world, and the / proc system only exists in memory and does not take up external memory space.

Each file under / proc is bound to a kernel function that dynamically generates the contents of the file as the user reads it. Kernel parameters can also be modified by writing / proc file

The file in the / proc directory analyzes / proc/$pid 's information directory about the process $pid. Each process has a directory under / proc called its process number. Example: $> strings-f / proc/ [0-9] * / cmdline

/ command line started by proc/cmdline kernel

/ proc/cpuinfo processor information, such as type, manufacturer, model, and performance.

/ proc/devices lists the primary device numbers of character and block devices, as well as the device names assigned to these device numbers

/ proc/dma displays the DMA channel currently in use.

/ proc/filesystems lists the types of file systems available for use, usually those written into the kernel, but new types can be added through modules

/ proc/interrupts displays the interrupt number used, the name of the interrupt, and the number of times these interrupts have occurred since the system was started

The iUnip O port currently used by / proc/ioports.

/ proc/kallsyms kernel symbol table. After installing the new module, it will be reflected here.

/ proc/kcore system physical memory image. It's exactly the same size as physical memory, but it doesn't actually take up that much memory; (remember: nothing under / proc takes up any disk space unless it's copied to a file)

Messages output by the / proc/kmsg kernel. Was also sent to syslog.

The average load of / proc/loadavg system, the first three are the load of the past 1 minute, 5 minutes, 15 minutes, then the number of running tasks and the total number of tasks, and finally the last process number of the last run

/ proc/meminfo memory usage information, including physical memory and swap.

Which core modules are currently loaded by / proc/modules.

Partition information of the hard disk currently mounted on the / proc/partitions system

/ pci bus information of proc/pci system

/ proc/net network protocol status information.

Symbolic link from / proc/self to the process directory of the program that views / proc. When two processes view / proc, it is a different connection. This is mainly convenient for the program to get its own process directory.

Allocation information of slab cache in / proc/slabinfo system

Some status information of / proc/stat system

Exchange area information used in / proc/swaps system

/ proc/sysrq-trigger is used to launch the sysRq key $> echo 1 > sysrq-trigger

The length of time that the / proc/uptime system is started and idle. For use by uptime

/ proc/version kernel version

(2) implement a / proc file by yourself

The header file 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

Uninstall proc files with remove_proc_entry

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 (that is, a block of PAGE_SIZE bytes of memory) that drives the data to be written back to user space through this memory page.

Typedef int (read_proc_t) (char * page, char * * start, off_t off,int count, int * eof, void * data); the above is all the contents of the article "sample Analysis of proc File system for Linux Kernel device drivers". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report