linux内核编程helloworld(中级)
传入参数
[root@bogon modules]# cat first.c
#include<linux/kernel.h>
#include<linux/stat.h>
#include<linux/moduleparam.h>
#include<linux/init.h>
#include<linux/module.h>
static short int a=1;
static int b=2;
static long int c=3;
static char *d="bp";
static int myintArray[2]={-1,-1};
static int arr_argc=0;
module_param(a,short,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
MODULE_PARM_DESC(a,"a short integer");
module_param(b,int ,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
MODULE_PARM_DESC(b,"an integer");
module_param(c,long,S_IRUSR);
MODULE_PARM_DESC(c,"a long integer");
module_param(d,charp,0000);
MODULE_PARM_DESC(d,"a char string");
module_param_array(myintArray,int,&arr_argc,0000);
MODULE_PARM_DESC(myintArray,"an array of integers");
static int __initdata hellodata=3;
static int __init bp_init(void){
int i;
printk(KERN_ALERT "hello world\n");
printk(KERN_ALERT "a is a short integer:%d\n",a);
printk(KERN_ALERT "b is a integer:%d\n",b);
printk(KERN_ALERT "c is a long integer:%d\n",c);
printk(KERN_ALERT "d is a string:%s\n",d);
for(i=0;i<(sizeof(myintArray)/sizeof(int));i++)
printk(KERN_ALERT "myintArray[%d] is %d\n",i,myintArray[i]);
printk(KERN_ALERT "\nhi,this is bp %d \n",hellodata);
return 0;
}
static void __exit bp_exit(void){
printk(KERN_ALERT "\ngoobye bp\n");
}
module_init(bp_init);
module_exit(bp_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("by bp");
MODULE_DESCRIPTION("this is test of bp");
MODULE_SUPPORTED_DEVICE("testdevice");
[root@bogon modules]# cat Makefile
obj-m=first.o
default:
make -C /usr/src/kernels/`uname -r` M=$(PWD) modules
clean:
make -C /usr/src/kernels/`uname -r` M=$(PWD) clean
[root@bogon modules]# make
make -C /usr/src/kernels/`uname -r` M=/root/modules modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-514.el7.x86_64'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/kernels/3.10.0-514.el7.x86_64'
[root@bogon modules]# insmod first.ko a=100
[root@bogon modules]# rmmod first
[root@bogon modules]#
运行效果
linux内核编程helloworld(中级)的更多相关文章
- Linux内核编程-0:来自内核的 HelloWorld
Linux内核编程一直是我很想掌握的一个技能.如果问我为什么,我也说不上来. 也许是希望有一天自己的ID也出现在内核开发组的邮件列表里?或是内核发行文件的CREDITS文件上? 也许是吧.其实更多的, ...
- 初探linux内核编程,参数传递以及模块间函数调用
一.前言 我们一起从3个小例子来体验一下linux内核编程.如下: 1.内核编程之hello world 2.模块参数传递 3.模块间 ...
- Linux内核编程规范与代码风格
source: https://www.kernel.org/doc/html/latest/process/coding-style.html translated by trav, travmym ...
- 宋宝华: Linux内核编程广泛使用的前向声明(Forward Declaration)
本文系转载,著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 作者:宋宝华 来源: 微信公众号linux阅码场(id: linuxdev) 前向声明 编程定律 先强调一点:在一切可 ...
- linux内核编程入门 hello world
注意: Makefile 文件的命名注意M需要大写,否则会报错. 在Makefile文件中make命令前应为tab制表符. 下文转载至:https://blog.csdn.net/bingqing07 ...
- linux内核编程入门--系统调用监控文件访问
参考的资料: hello world https://www.cnblogs.com/bitor/p/9608725.html linux内核监控模块--系统调用的截获 https://www. ...
- linux内核编程笔记【原创】
以下为本人学习笔记,如有转载请注明出处,谢谢 DEFINE_MUTEX(buzzer_mutex); mutex_lock(&buzzer_mutex); mutex_unlock(& ...
- Linux内核编程、调试技巧小集
1. 内核中通过lookup_symbol_name获取函数名称 内核中很多结构体成员是函数,有时可能比较复杂不知道具体使用哪一个函数.这是可以通过lookup_symbol_name来获取符号表名称 ...
- Linux内核编程、调试技巧小集【转】
转自:https://www.cnblogs.com/arnoldlu/p/7152488.html 1. 内核中通过lookup_symbol_name获取函数名称 内核中很多结构体成员是函数,有时 ...
随机推荐
- svn服务器搭建及使用(一)
这里郑重感谢分享作者的辛苦:http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html Subversion是优秀的版本控制工 ...
- 每天CSS学习之text-decoration
text-decoration是CSS的一个属性,其作用是给文本装饰上划线.中间线.下划线或不装饰.其值如下所示: 1.none:不装饰任何线.该值是默认值.如下所示: p{ text-decorat ...
- html回顾随笔1(*^__^*)
1.text—align 与float 区别: float是针对div一类的容器来说.text-align是对于容器里的文本或者图片来说靠左或靠右水平对齐(vlign 竖直方向) 要注意以下几点: ...
- spring的配置文件解析(转)
http://www.cnblogs.com/as-dreamer/p/6523215.html 我们在使用Spring框架的时候首先要配置其xml文件,大量的头信息到底代表了什么呢,在这里总结下自己 ...
- SharePoint Framework 企业向导(七)
博客地址:http://blog.csdn.net/FoxDave 企业中的SPFx SharePoint是最成功的企业协作平台之一,能够成功的其中一点是它能够进行扩展并作为一个应用集成平台.SP ...
- 5.Python爬虫入门五之URLError异常处理
大家好,本节在这里主要说的是URLError还有HTTPError,以及对它们的一些处理. 1.URLError 首先解释下URLError可能产生的原因: 网络无连接,即本机无法上网 连接不到特定的 ...
- Arduino 串口输出LM35温度
#include "stdlib.h" float temp = 0.0; float maxtemp = 0.0; float mintemp =100.0; // the se ...
- shell日常实战练习——通过监视用户登陆找到入侵者
#!/usr/bin/bash #用户检测入侵工具 AUTHLOG=/var/log/secure if [[ -n $1 ]];then AUTHLOG=$1 echo "Using Lo ...
- shell脚本实例-安装httpd,安装yum源
1.安装httpd #!/usr/bin/bash getway=192.168.1.1 ping -c1 www.baidu.com &>/dev/null if [ $? -eq 0 ...
- python之pandas简单介绍及使用(一)
python之pandas简单介绍及使用(一) 一. Pandas简介1.Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据 ...