传入参数

  1. [root@bogon modules]# cat first.c
  2. #include<linux/kernel.h>
  3. #include<linux/stat.h>
  4. #include<linux/moduleparam.h>
  5. #include<linux/init.h>
  6. #include<linux/module.h>
  7. static short int a=1;
  8. static int b=2;
  9. static long int c=3;
  10. static char *d="bp";
  11. static int myintArray[2]={-1,-1};
  12. static int arr_argc=0;
  13. module_param(a,short,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
  14. MODULE_PARM_DESC(a,"a short integer");
  15. module_param(b,int ,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
  16. MODULE_PARM_DESC(b,"an integer");
  17. module_param(c,long,S_IRUSR);
  18. MODULE_PARM_DESC(c,"a long integer");
  19. module_param(d,charp,0000);
  20. MODULE_PARM_DESC(d,"a char string");
  21. module_param_array(myintArray,int,&arr_argc,0000);
  22. MODULE_PARM_DESC(myintArray,"an array of integers");
  23. static int __initdata hellodata=3;
  24. static int __init bp_init(void){
  25. int i;
  26. printk(KERN_ALERT "hello world\n");
  27. printk(KERN_ALERT "a is a short integer:%d\n",a);
  28. printk(KERN_ALERT "b is a integer:%d\n",b);
  29. printk(KERN_ALERT "c is a long integer:%d\n",c);
  30. printk(KERN_ALERT "d is a string:%s\n",d);
  31. for(i=0;i<(sizeof(myintArray)/sizeof(int));i++)
  32. printk(KERN_ALERT "myintArray[%d] is %d\n",i,myintArray[i]);
  33. printk(KERN_ALERT "\nhi,this is bp %d \n",hellodata);
  34. return 0;
  35. }
  36. static void __exit bp_exit(void){
  37. printk(KERN_ALERT "\ngoobye bp\n");
  38. }
  39. module_init(bp_init);
  40. module_exit(bp_exit);
  41. MODULE_LICENSE("GPL");
  42. MODULE_AUTHOR("by bp");
  43. MODULE_DESCRIPTION("this is test of bp");
  44. MODULE_SUPPORTED_DEVICE("testdevice");
  45. [root@bogon modules]# cat Makefile
  46. obj-m=first.o
  47. default:
  48. make -C /usr/src/kernels/`uname -r` M=$(PWD) modules
  49. clean:
  50. make -C /usr/src/kernels/`uname -r` M=$(PWD) clean
  51. [root@bogon modules]# make
  52. make -C /usr/src/kernels/`uname -r` M=/root/modules modules
  53. make[1]: Entering directory `/usr/src/kernels/3.10.0-514.el7.x86_64'
  54. Building modules, stage 2.
  55. MODPOST 1 modules
  56. make[1]: Leaving directory `/usr/src/kernels/3.10.0-514.el7.x86_64'
  57. [root@bogon modules]# insmod first.ko a=100
  58. [root@bogon modules]# rmmod first
  59. [root@bogon modules]#

运行效果

linux内核编程helloworld(中级)的更多相关文章

  1. Linux内核编程-0:来自内核的 HelloWorld

    Linux内核编程一直是我很想掌握的一个技能.如果问我为什么,我也说不上来. 也许是希望有一天自己的ID也出现在内核开发组的邮件列表里?或是内核发行文件的CREDITS文件上? 也许是吧.其实更多的, ...

  2. 初探linux内核编程,参数传递以及模块间函数调用

    一.前言                                  我们一起从3个小例子来体验一下linux内核编程.如下: 1.内核编程之hello world 2.模块参数传递 3.模块间 ...

  3. Linux内核编程规范与代码风格

    source: https://www.kernel.org/doc/html/latest/process/coding-style.html translated by trav, travmym ...

  4. 宋宝华: Linux内核编程广泛使用的前向声明(Forward Declaration)

    本文系转载,著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 作者:宋宝华 来源: 微信公众号linux阅码场(id: linuxdev) 前向声明 编程定律 先强调一点:在一切可 ...

  5. linux内核编程入门 hello world

    注意: Makefile 文件的命名注意M需要大写,否则会报错. 在Makefile文件中make命令前应为tab制表符. 下文转载至:https://blog.csdn.net/bingqing07 ...

  6. linux内核编程入门--系统调用监控文件访问

    参考的资料: hello world   https://www.cnblogs.com/bitor/p/9608725.html linux内核监控模块--系统调用的截获  https://www. ...

  7. linux内核编程笔记【原创】

    以下为本人学习笔记,如有转载请注明出处,谢谢 DEFINE_MUTEX(buzzer_mutex); mutex_lock(&buzzer_mutex); mutex_unlock(& ...

  8. Linux内核编程、调试技巧小集

    1. 内核中通过lookup_symbol_name获取函数名称 内核中很多结构体成员是函数,有时可能比较复杂不知道具体使用哪一个函数.这是可以通过lookup_symbol_name来获取符号表名称 ...

  9. Linux内核编程、调试技巧小集【转】

    转自:https://www.cnblogs.com/arnoldlu/p/7152488.html 1. 内核中通过lookup_symbol_name获取函数名称 内核中很多结构体成员是函数,有时 ...

随机推荐

  1. elasticsearch基本操作之--使用QueryBuilders进行查询

    /** * 系统环境: vm12 下的centos 7.2 * 当前安装版本: elasticsearch-2.4.0.tar.gz */ QueryBuilder 是es中提供的一个查询接口, 可以 ...

  2. net core2 采坑-- session 缓存

    引用 Microsoft.Extensions.Caching.SqlServer 可以设置存在数据库 Microsoft.Extensions.Caching.Redis 存在redis 参考 ht ...

  3. centos7配置mysql

    一:mysql安装方法一:yum安装 下载并安装MySQL官方的 Yum Repository https://dev.mysql.com/ cd ~ wget -i -c https://dev.m ...

  4. [SCOI2005]栅栏

    这个题...只能说比较水... 排序后,算一个前缀和,二分dfs查找答案...加上两个剪枝就过了...QVQ 我只能刷这种水题...我太菜了...QVQ #include<iostream> ...

  5. Java内存模式

    Java内存模型即Java Memory Model,简称JMM.JMM定义了Java 虚拟机(JVM)在计算机内存(RAM)中的工作方式. JVM是Java Virtual Machine(Java ...

  6. 记录搭建ssm项目

    搞java也快3年了,搭建一个ssm居然有点吃力. 参考链接:https://blog.csdn.net/gebitan505/article/details/44455235/ 环境准备:jdk8. ...

  7. springMvc 简单搭建

    1.pom.xml 依赖引入 2.配置web.xml 3.配置 springMvc.xml 4.配置 logback.xml 5.编写 controller 测试 1.pom.xml 依赖引入 < ...

  8. ClickOnce 和管理员权限

    有些程序需要管理员权限需要运行,同时又想用ClickOnce进行发布,这时候就麻烦了,两者是互斥的. 解决方案是,去掉管理员权限的要求,可以进行发布. 程序启动的时候,加载程序员权限的请求. 代码如下 ...

  9. L268 A terrifying look at the consequences of climate change

    Climate change is a devilish problem for humanity: at once urgent and slow-moving, immediate and dis ...

  10. 转-Asynchronous bulk transfer using libusb

    https://falsinsoft.blogspot.jp/2015/02/asynchronous-bulk-transfer-using-libusb.html The 'linusb' is ...