使用proc介面例子

2021-07-22 09:55:45 字數 794 閱讀 7809

proc.c的檔案內容為

#include #include #include static int hello_proc_show(struct seq_file *m, void *v)

ssize_t test_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)

static int hello_proc_open(struct inode *inode, struct file *file)

static const struct file_operations hello_proc_fops =

;static int __init hello_proc_init(void)

static void __exit hello_proc_exit(void)

module_license("gpl");

module_init(hello_proc_init);

module_exit(hello_proc_exit);

安裝該驅動後,在proc下出現hello_proc檔案,可通過echo和cat來讀寫檔案。

root@w-lenovo-g470:/proc# ls -al hello_proc 

-rwxrwxrwx 1 root root 0 9月 4 20:58 hello_proc

該驅動在核心3.10之後的版本才可以用,核心3.10的的可參考

Pro C 簡單例子

include exec sql begin declare section char userid 11 hr oracle char std name 10 int std number int dept number exec sql end declare section char temp...

使用 proc測試

下面所示清單為乙個簡單的 proc 使用範例,這段 在模組載入函式中建立 proc 檔案節點,在模組解除安裝函式中撤銷 proc 節點,檔案中儲存了乙個32位無符號整形值。include include include static struct proc dir entry proc entry ...

pro c初學2 簡單多執行緒例子

name proc mul.pc 預編譯條件 mode oracle parse full 利用多執行緒,更新表中記錄 每個執行緒擁有單獨的上下文環境 表結構 create table accounts account number 36 balance 36,2 include include i...