本文转载自:http://blog.csdn.net/mike8825/article/details/52434666

版权声明:本文为博主原创文章,未经博主允许不得转载。

在上一篇的使用sys接口来调试驱动的写完后,这里也将proc接口的例子贴出来。

proc.c的文件内容为

  1. #include <linux/module.h>
  2. #include <linux/proc_fs.h>
  3. #include <linux/seq_file.h>
  4. static int hello_proc_show(struct seq_file *m, void *v)
  5. {
  6.     seq_printf(m, "Hello proc!\n");
  7.     return 0;
  8. }
  9. ssize_t test_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
  10. {
  11. unsigned int var;
  12. var=simple_strtoul(buffer,NULL,10);
  13. printk("var=%d\n",var);
  14. return count;
  15. }
  16. static int hello_proc_open(struct inode *inode, struct  file *file)
  17. {
  18.      return single_open(file, hello_proc_show, NULL);
  19. }
  20. static const struct file_operations hello_proc_fops =
  21. {
  22. .owner   = THIS_MODULE,
  23. .open    = hello_proc_open,
  24. .read    = seq_read,
  25. .write   = test_proc_write,
  26. .llseek  = seq_lseek,
  27. .release = single_release,
  28. };
  29. static int __init hello_proc_init(void)
  30. {
  31. proc_create("hello_proc", S_IRWXUGO, NULL, &hello_proc_fops);
  32. return 0;
  33. }
  34. static void __exit hello_proc_exit(void)
  35. {
  36.      remove_proc_entry("hello_proc", NULL);
  37. }
  38. MODULE_LICENSE("GPL");
  39. module_init(hello_proc_init);
  40. module_exit(hello_proc_exit);

安装该驱动后,在proc下出现hello_proc文件,可通过echo和cat来读写文件。

  1. root@w-Lenovo-G470:/proc# ls -al hello_proc
  2. -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接口例子【转】的更多相关文章

  1. 微软手写识别模块sdk及delphi接口例子

    http://download.csdn.net/download/coolstar1204/2008061 微软手写识别模块sdk及delphi接口例子

  2. Spring Boot Hello World (restful接口)例子

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  3. linux /proc 接口和共享中断

    在系统中安装共享处理者不影响 /proc/stat, 它甚至不知道处理者. 但是, /proc/interrupts 稍稍变化. 所有同一个中断号的安装的处理者出现在 /proc/interrupts ...

  4. 使用httpclient访问NLP应用接口例子

    参考网址: http://yuzhinlp.com/docs.html 接入前须知 接入条件 1.进入网站首页,点击注册成为语知科技用户 2.注册完成后,系统将提供语知科技用户唯一标识APIKey,并 ...

  5. linux /proc 接口

    无论何时一个硬件中断到达处理器, 一个内部的计数器递增, 提供了一个方法来检查设备 是否如希望地工作. 报告的中断显示在 /proc/interrupts. 下面的快照取自一个双处理 器 Pentiu ...

  6. Proc文件系统接口调试

    在tpd_i2c_probe I2C的探测函数中创建proc接口 //----------------------------------------------------------------- ...

  7. Java中的内部接口

    什么是内部接口 内部接口也称为嵌套接口,即在一个接口内部定义另一个接口.举个例子,Entry接口定义在Map接口里面,如下代码: public interface Map { interface En ...

  8. PHP面向对象学习五 类中接口的应用

    类中接口的应用 接口:一种成员属性全部为抽象的特殊抽象类,在程序中同为规范的作用   抽象类:1.类中至少有一个抽象方法.2.方法前需要加abstract 接口: 1.类中全部为抽象方法,抽象方法前不 ...

  9. Unit05 - 抽象类、接口和内部类(上)

    Unit05 - 抽象类.接口和内部类(上) 1.static final常量:  1)必须声明同时初始化  2)通过类名来访问,不能被改变  3)建议:常量名所有字母都大写(多个单词间用_)  4) ...

随机推荐

  1. *AtCoder Regular Contest 094 F - Normalization

    $n \leq 200000$的abc字符串,现能进行如下变换零次或若干次:选一个$i<n$且$s_i \neq s_{i+1}$,把$s_i$和$s_{i+1}$替换成abc三个字母中除了这两 ...

  2. Mac快速查看隐藏文件

    使用终端 显示隐藏文件的最简单方法是使用终端.只要打开终端(位于应用程序--实用工具),将以下代码复制进去然后回车 defaults write com.apple.finder AppleShowA ...

  3. 记录一下 ps命令找出线程占用cpu情况

    https://blog.csdn.net/xnn2s/article/details/11865339

  4. 同时在windows和linux环境开发时换行符的处理

    Git 的 core.autocrlf 參數默认为true,即每次 checkin 時,Git 會將純文字類型的檔案中的所有 CRLF 字元轉換為 LF,也就是版本庫中的換行符號一律存成 LF:在 c ...

  5. R读数据stringsAsFactors=F,存数据时row.names = F

    stringsAsFactors=F   以前在r里读数据,经常把character读成factor,还得费半天劲把它转回来,尤其是把factor转成numeric还没有那么直接.例如: dat< ...

  6. Go -- RPC 之 Thrift

    Thrift 简介: Thrift 是一款高性能.开源的 RPC 框架,产自 Facebook 后贡献给了 Apache,Thrift 囊括了整个 RPC 的上下游体系,自带序列化编译工具,因为 Th ...

  7. Python基础语法04-数据结构

    Python Number(数字) Python Number 数据类型用于存储数值. 数据类型是不允许改变的,这就意味着如果改变 Number 数据类型的值,将重新分配内存空间. Python 支持 ...

  8. 33.JAVA编程思想——JAVA IO File类

    33.JAVA编程思想--JAVA IO File类 RandomAccessFile用于包括了已知长度记录的文件.以便我们能用 seek()从一条记录移至还有一条:然后读取或改动那些记录. 各记录的 ...

  9. pomelo加入定时任务

    需求:在arenaserver下添加一个rank定时任务,每一分钟对对玩家进行一次排行. 首先在game-server/app/servers/arena文件夹下添加cron文件夹. 在game-se ...

  10. Indri和Terrier搜索引擎的使用

    介绍 Indri和Terrier都是开源的搜索引擎,当中Indri作为Lemur项目的一个重要部分,具有强大的查询接口,易建索引,可扩展,高效率等长处.能够在SourceForge Lemur Pro ...