使用proc接口例子【转】
本文转载自:http://blog.csdn.net/mike8825/article/details/52434666
版权声明:本文为博主原创文章,未经博主允许不得转载。
在上一篇的使用sys接口来调试驱动的写完后,这里也将proc接口的例子贴出来。
proc.c的文件内容为
- #include <linux/module.h>
- #include <linux/proc_fs.h>
- #include <linux/seq_file.h>
- static int hello_proc_show(struct seq_file *m, void *v)
- {
- seq_printf(m, "Hello proc!\n");
- return 0;
- }
- ssize_t test_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
- {
- unsigned int var;
- var=simple_strtoul(buffer,NULL,10);
- printk("var=%d\n",var);
- return count;
- }
- static int hello_proc_open(struct inode *inode, struct file *file)
- {
- return single_open(file, hello_proc_show, NULL);
- }
- static const struct file_operations hello_proc_fops =
- {
- .owner = THIS_MODULE,
- .open = hello_proc_open,
- .read = seq_read,
- .write = test_proc_write,
- .llseek = seq_lseek,
- .release = single_release,
- };
- static int __init hello_proc_init(void)
- {
- proc_create("hello_proc", S_IRWXUGO, NULL, &hello_proc_fops);
- return 0;
- }
- static void __exit hello_proc_exit(void)
- {
- remove_proc_entry("hello_proc", NULL);
- }
- 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的的可参考http://blog.csdn.net/a_ran/article/details/37626765
使用proc接口例子【转】的更多相关文章
- 微软手写识别模块sdk及delphi接口例子
http://download.csdn.net/download/coolstar1204/2008061 微软手写识别模块sdk及delphi接口例子
- Spring Boot Hello World (restful接口)例子
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- linux /proc 接口和共享中断
在系统中安装共享处理者不影响 /proc/stat, 它甚至不知道处理者. 但是, /proc/interrupts 稍稍变化. 所有同一个中断号的安装的处理者出现在 /proc/interrupts ...
- 使用httpclient访问NLP应用接口例子
参考网址: http://yuzhinlp.com/docs.html 接入前须知 接入条件 1.进入网站首页,点击注册成为语知科技用户 2.注册完成后,系统将提供语知科技用户唯一标识APIKey,并 ...
- linux /proc 接口
无论何时一个硬件中断到达处理器, 一个内部的计数器递增, 提供了一个方法来检查设备 是否如希望地工作. 报告的中断显示在 /proc/interrupts. 下面的快照取自一个双处理 器 Pentiu ...
- Proc文件系统接口调试
在tpd_i2c_probe I2C的探测函数中创建proc接口 //----------------------------------------------------------------- ...
- Java中的内部接口
什么是内部接口 内部接口也称为嵌套接口,即在一个接口内部定义另一个接口.举个例子,Entry接口定义在Map接口里面,如下代码: public interface Map { interface En ...
- PHP面向对象学习五 类中接口的应用
类中接口的应用 接口:一种成员属性全部为抽象的特殊抽象类,在程序中同为规范的作用 抽象类:1.类中至少有一个抽象方法.2.方法前需要加abstract 接口: 1.类中全部为抽象方法,抽象方法前不 ...
- Unit05 - 抽象类、接口和内部类(上)
Unit05 - 抽象类.接口和内部类(上) 1.static final常量: 1)必须声明同时初始化 2)通过类名来访问,不能被改变 3)建议:常量名所有字母都大写(多个单词间用_) 4) ...
随机推荐
- 【单调队列】poj 2823 Sliding Window
http://poj.org/problem?id=2823 [题意] 给定一个长度为n的序列,求长度为k的滑窗内的最大值和最小值 [思路] 裸的单调队列 注意用C++提交,不然会T,orz我用G++ ...
- 【NOI Linux】复习一波命令行
$linux$ 终端真是用不惯. 假设 a 是一个可执行文件( $linux$ 下的可执行文件没有后缀 ) 1. size a 计算一个程序的静态内存(全局数组变量.栈空间.堆空间等),单位是字节.除 ...
- bzoj1853: [Scoi2010]幸运数字 dp+容斥原理
在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是“幸运号码”!但是这种“幸运号码”总是 ...
- 使用putty上传下载文件(pscp)
putty作为ssh工具开源免费,简单易用.可是如何使用它来上传和下载文件呢?答案在于pscp. pscp下载地址:http://www.chiark.greenend.org.uk/~sgtatha ...
- Codeforces961F. k-substrings
$n \leq 1000000$的字符串,对每一个子串$i$~$n-i+1$,求他最长的一个既是前缀又是后缀的子串. 这题要求的东西具有“对称性”,不充分利用难以解决.这里的“对称性”不仅指询问是对称 ...
- excel打乱各行的顺序,实现无序随机排列
由于公司做活动,经常会发些激活码过来,为了让激活码能够充分使用,经常要打乱激活码的顺序,百度了下,看了下网上的介绍,还不错,挺实用,记录下来. 具体方法如下: 1.将文本里的内容复制到Excel里的任 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- cannot find package "golang.org/x/crypto/pbkdf2" in any of:
cannot find package "golang.org/x/crypto/pbkdf2" in any of: /Users/zhou/go/src/mos.market/ ...
- Controller配置汇总
1.通过Url对应Bean <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping ...
- 531. Lonely Pixel I
Given a picture consisting of black and white pixels, find the number of black lonely pixels. The pi ...