本文转载自: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. Swift3.0 函数闭包与 Block

    刚接触Swift,如有不对,欢迎指正 Swift中定义一个基本函数 //定义一个函数,接收一个字符串,返回一个String类型的值 func test(name:String) -> Strin ...

  2. PHP实现当前文件夹下所有文件和文件夹的遍历

    <?php function myScandir($dir){ static $flag=''; //设置缩进显示格式 $files = scandir($dir);//读取当前文件夹的文件 $ ...

  3. 设置好uTorrent让你的下载速度飞起来

    由于有会员反映下载国外种子速度很慢的问题,而我下同样的种子,竟然那天下载最高速度能到500K/秒.(我用的是移动的校园网,这种出了名的烂网,十天有七天是图片都打不开的网)这可见是所用软件和软件的设置问 ...

  4. spring--路由

    @RestController: Spring4之后新加入的注解,原来返回json需要@ResponseBody和@Controller配合. 即@RestController是@ResponseBo ...

  5. 【微信小程序】开发实战 之 「配置项」与「逻辑层」

    微信小程序作为微信生态重要的一环,在实际生活.工作.商业中的应用越来越广泛.想学习微信小程序开发的朋友也越来越多,本文将在小程序框架的基础上就微信小程序项目开发所必需的基础知识及语法特点进行了详细总结 ...

  6. 关于Lisp和函数式编程 & 各种语言对比 & TIOBE

    上一篇文章提到了,今天又读到Lisp的一些内容 <为什么Lisp如此先进>ruanyifeng(Link).关于Lisp的八卦,可以参考我前面两篇文章 http://www.cnblogs ...

  7. [转]PHP并发IO编程之路(深度长文)

    原文:https://www.imooc.com/article/8449 -------------------------------------------------------------- ...

  8. linux find 命令查找 复制

    find 查找 find . -mtime -2 -a -path './.git*' -prune , -path './Cache' -prune -a -exec cp {} one \; rm ...

  9. flex 操作xml 实现增删改查 .

    一 在介绍Flex中操作XML之前,首先简单介绍下XML中的基本术语. 元素:XML中拥有开始标签和结束标签的这一块称为“元素”    节点:把XML元素与文本结合起来统称为节点    根节点:位于整 ...

  10. windows服务 MVC之@Html.Raw()用法 文件流的读写 简单工厂和工厂模式对比

    windows服务   public partial class Service1 : ServiceBase{ System.Threading.Timer recordTimer;public S ...