本文转载自: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. vue之二级路由

    router-view : <router-view> 组件是一个 functional 组件,渲染路径匹配到的视图组件 一 样式 1 在一个vue组件,<template>& ...

  2. 连接mysql报错 : The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone...

    time zone 时区错误 DBEAVER连接MySQL运行报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or repres ...

  3. 简化LINUX的命令输入 简化linux命令 快捷键 短路径

    在LINUX中,有很多常用的命令,常用的命令我们可以熟练的记忆,但是对于不经常使用的命令恐怕是需要翻阅手册了,但是我们可以简化这些命令的输入来达到简便记忆的效果. 这里以BSH为例: 编辑/etc/b ...

  4. yum gd linux

    32位操作系统安装命令:[root@localhost ~]# yum install php-gd*64位操作系统安装命令:[root@localhost ~]# yum install php-g ...

  5. 浅谈Heatmap

    在自然界之中,蛇的眼睛有夜视功能,即便是茫茫黑夜,它也能轻而易举的找到猎物,这是因为任何物体都会辐射热红外,且辐射的高低和温度成正比,由于生命体的体温会明显高于周围环境的温度,所以在蛇眼面前便无处遁形 ...

  6. 【J2EE】十三个规范:愿天下苍生,人人如猿。

    学习了J2ee后对java这个立足标准化的行为感到深深的佩服. 收买什么都不如收买人心,培养啥子都不如培养 习惯.没错,java就是在培养行业习惯,以一纸规范屹立不倒.毕竟技术什么的层出不穷,再新再前 ...

  7. 转:CEO, CFO, CIO, CTO, CSO是什么

    转自:https://club.1688.com/threadview/26957122.html CEO, CFO, CIO, CTO, CSO是什么?(现在O太多了) 帖子创建时间:  2009年 ...

  8. [React] Create and import React components with Markdown using MDXC

    In this lesson I demonstrate how to use the library MDXC to create and import React components with ...

  9. weex 项目开发(三) weexpack + weex-ui

    github地址:weex-ui https://github.com/alibaba/weex-ui 官网: https://alibaba.github.io/weex-ui/#/cn/ 创建项目 ...

  10. Ubuntu搭建Android开发环境

    前言 由于迁移到新的笔记本,所以Android开发环境须要又一次配置了.android官网有配置教程,我正好回想一遍 配置Java环境 下载jdk.官网地址:http://www.oracle.com ...