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获取函数名称 内核中很多结构体成员是函数,有时 ...
随机推荐
- elasticsearch基本操作之--使用QueryBuilders进行查询
/** * 系统环境: vm12 下的centos 7.2 * 当前安装版本: elasticsearch-2.4.0.tar.gz */ QueryBuilder 是es中提供的一个查询接口, 可以 ...
- net core2 采坑-- session 缓存
引用 Microsoft.Extensions.Caching.SqlServer 可以设置存在数据库 Microsoft.Extensions.Caching.Redis 存在redis 参考 ht ...
- centos7配置mysql
一:mysql安装方法一:yum安装 下载并安装MySQL官方的 Yum Repository https://dev.mysql.com/ cd ~ wget -i -c https://dev.m ...
- [SCOI2005]栅栏
这个题...只能说比较水... 排序后,算一个前缀和,二分dfs查找答案...加上两个剪枝就过了...QVQ 我只能刷这种水题...我太菜了...QVQ #include<iostream> ...
- Java内存模式
Java内存模型即Java Memory Model,简称JMM.JMM定义了Java 虚拟机(JVM)在计算机内存(RAM)中的工作方式. JVM是Java Virtual Machine(Java ...
- 记录搭建ssm项目
搞java也快3年了,搭建一个ssm居然有点吃力. 参考链接:https://blog.csdn.net/gebitan505/article/details/44455235/ 环境准备:jdk8. ...
- springMvc 简单搭建
1.pom.xml 依赖引入 2.配置web.xml 3.配置 springMvc.xml 4.配置 logback.xml 5.编写 controller 测试 1.pom.xml 依赖引入 < ...
- ClickOnce 和管理员权限
有些程序需要管理员权限需要运行,同时又想用ClickOnce进行发布,这时候就麻烦了,两者是互斥的. 解决方案是,去掉管理员权限的要求,可以进行发布. 程序启动的时候,加载程序员权限的请求. 代码如下 ...
- 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 ...
- 转-Asynchronous bulk transfer using libusb
https://falsinsoft.blogspot.jp/2015/02/asynchronous-bulk-transfer-using-libusb.html The 'linusb' is ...