传入参数

  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. svn服务器搭建及使用(一)

    这里郑重感谢分享作者的辛苦:http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html Subversion是优秀的版本控制工 ...

  2. 每天CSS学习之text-decoration

    text-decoration是CSS的一个属性,其作用是给文本装饰上划线.中间线.下划线或不装饰.其值如下所示: 1.none:不装饰任何线.该值是默认值.如下所示: p{ text-decorat ...

  3. html回顾随笔1(*^__^*)

    1.text—align 与float 区别: float是针对div一类的容器来说.text-align是对于容器里的文本或者图片来说靠左或靠右水平对齐(vlign 竖直方向) 要注意以下几点:   ...

  4. spring的配置文件解析(转)

    http://www.cnblogs.com/as-dreamer/p/6523215.html 我们在使用Spring框架的时候首先要配置其xml文件,大量的头信息到底代表了什么呢,在这里总结下自己 ...

  5. SharePoint Framework 企业向导(七)

    博客地址:http://blog.csdn.net/FoxDave 企业中的SPFx SharePoint是最成功的企业协作平台之一,能够成功的其中一点是它能够进行扩展并作为一个应用集成平台.SP ...

  6. 5.Python爬虫入门五之URLError异常处理

    大家好,本节在这里主要说的是URLError还有HTTPError,以及对它们的一些处理. 1.URLError 首先解释下URLError可能产生的原因: 网络无连接,即本机无法上网 连接不到特定的 ...

  7. Arduino 串口输出LM35温度

    #include "stdlib.h" float temp = 0.0; float maxtemp = 0.0; float mintemp =100.0; // the se ...

  8. shell日常实战练习——通过监视用户登陆找到入侵者

    #!/usr/bin/bash #用户检测入侵工具 AUTHLOG=/var/log/secure if [[ -n $1 ]];then AUTHLOG=$1 echo "Using Lo ...

  9. shell脚本实例-安装httpd,安装yum源

    1.安装httpd #!/usr/bin/bash getway=192.168.1.1 ping -c1 www.baidu.com &>/dev/null if [ $? -eq 0 ...

  10. python之pandas简单介绍及使用(一)

    python之pandas简单介绍及使用(一) 一. Pandas简介1.Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据 ...