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获取函数名称 内核中很多结构体成员是函数,有时 ...
随机推荐
- springmvc添加拦截器
springmvc.xml配置如下: 除了 sysFile 下的所有接口,以及user下的loginUser接口,其他的所有接口都会经过拦截器UserInterceptor处理 <mvc:int ...
- WinPcap是用于网络封包抓取的一套工具
WinPcap是用于网络封包抓取的一套工具,可适用于32位的操作平台上解析网络封包,包含了核心的封包过滤,一个底层动态链接库,和一个高层系统函数库,及可用来直接存取封包的应用程序界面. Winpcap ...
- centos installation of matlab R2015b
the source of installation is in the website: http://blog.csdn.net/hejunqing14/article/details/50265 ...
- [Spring]初识Spring-Spring是什么?如何实例化一个Spring容器?
关于Spring入门的基础知识点 Spring简介 Spring是由Rod Johnson创建的轻量型容器,目的在于简化企业级开发.是一种容器框架 a.降低侵入性 b.提供了IOC(控制反转)和AOP ...
- python基础题型一
一.执行Python脚本的两种方式 #python name.py Python解析器 #chmod +x name.py 二.简述位.字节的关系 1Byte=8bit 三.简述ascii.uni ...
- java学习笔记6(面向对象1:概念,private)
1.思想: 面向过程的思想:遇到问题时想,我该如何做,然后分步骤实现: 面向对象的思想:遇到问题时想,我该派谁去做这件事,至于他怎么做,与我无关,我只要最后的结果. 实际举例:我们要组装一台电脑: 面 ...
- DIV垂直居中对齐
效果图: CSS: #container{ display:table-cell; width:300px; height:300px; vertical-align:middle; border:1 ...
- java多线程和Calendar(日历)常用API
一.进程与线程 进程是一个可执行的程序一次运行的过程 线程是程序中的一个执行流 一个线程只能属于一个进程,而一个进程可以有多个线程,但至少有一个主线程 二.Calendar import java.u ...
- python调用caffe环境配置
背景是这样的,项目需要,必须将训练的模型通过C++进行调用,所以必须使用caffe或者mxnet,而caffe是用C++实现,所以有时候简单的加载一张图片然后再进行预测十分不方便 用caffe写pro ...
- 单调栈的运用-bzoj1012(代码转载-http://hzwer.com/1130.html)
Description 现在请求你维护一个数列,要求提供以下两种操作: . 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. . 插 ...