Proc-fs programming and proc-fs Programming
I. Introduction
The Proc file system is a pseudo-File System (Virtual File System) on Linux. It stores a series of special files in the running status of the current kernel, you can use these files to view the system hardware and currently running processes, or even change the running status of the kernel by changing some of these files.
Based on the particularity described above in the/proc file system, the files in it are also called virtual files and have some unique characteristics. To facilitate viewing and usage, these files are usually stored in different directories and even subdirectories by relevance, for example, the/proc/scsi directory stores information about all SCSI devices in the current system, and the/proc/N stores information about the processes currently running in the system, where N is a running process (as you can imagine, the related directory will disappear after a process ends ).
Ii. API
http://oss.org.cn/ossdocs/gnu_linux/kernel-api/
1. add or delete directories or files of the basic proc file system
struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode, struct proc_dir_entry *parent);struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode, struct proc_dir_entry *parent);struct proc_dir_entry *proc_create(const char *name, mode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops)struct proc_dir_entry *proc_create_data(const char *name, mode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops, void *data);void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
2. Add special proc files
1)/proc/net/
struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name, struct proc_dir_entry *parent);void proc_net_remove(struct net *net, const char *name);struct proc_dir_entry *proc_net_fops_create(struct net *net, const char *name, mode_t mode, const struct file_operations *fops);
2)/proc/sys/
Iii. Instances
http://www.mamicode.com/info-detail-96547.html
Reference: http://www.chinaitlab.com/linux/administer/889804.html