linux内核编程helloworld(中级)
来源:互联网 发布:阿里孙正义马云占股份 编辑:程序博客网 时间:2024/06/05 19:05
传入参数
[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.odefault: make -C /usr/src/kernels/`uname -r` M=$(PWD) modulesclean: make -C /usr/src/kernels/`uname -r` M=$(PWD) clean[root@bogon modules]# makemake -C /usr/src/kernels/`uname -r` M=/root/modules modulesmake[1]: Entering directory `/usr/src/kernels/3.10.0-514.el7.x86_64' Building modules, stage 2. MODPOST 1 modulesmake[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]#
运行效果
阅读全文
0 0
- linux内核编程helloworld(中级)
- Linux内核模块编程-HelloWorld
- Linux内核模块编程之Helloworld(初级)
- Linux内核模块编程之Helloworld!
- Linux内核模块编程之helloworld
- linux c编程 多线程(中级)
- Linux 内核模块 helloworld
- Linux v2.6内核编程之最简单的内核模块helloworld
- 内核模块编程---helloworld简单入门程序(1)
- linux shell编程 HelloWorld
- Linux内核开发之Helloworld
- Linux内核开发之Helloworld
- linux内核驱动01-helloworld
- (一)为Android系统编写Linux内核驱动程序HelloWorld
- Java 编程----(二.中级)
- Linux 内核编程(1)
- linux socket编程实例 helloworld
- Linux C编程(1) HelloWorld
- [Unity&Photon&代码问题&代码分析]右键移动 目标 位置偏差
- 解决下载的chm无法显示内容的问题
- 加载数据时先显示小圆圈不显示内容
- U3D 安卓通过openssl创建的电子证书进行HTTPS 加密访问
- 【Linux网络编程】I/O多路转接之 epoll 高性能简洁http服务器模型
- linux内核编程helloworld(中级)
- GOLANG最容易做测试MOCK
- cocos2d-js开发ios项目,按home键导致音效不能播放
- pixhawk博客导读
- SDUT 3895 fireworks 山东第八届ACM大赛C题(组合数学(杨辉三角)+逆元)
- bzoj3529 [Sdoi2014]数表
- 迭代器的原理和使用
- 关于TTMS影院系统的总结
- AI 1