HelloWorld 模块
2024-09-27 19:11:22
helloworld.c 代码
#include <linux/init.h>
#include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void)
{
printk(KERN_ALERT "Hello world\n");
return ;
} static void hello_exit(void)
{
printk(KERN_ALERT "goodbye,cruel world\n");
} module_init(hello_init);
module_exit(hello_exit);
Makefile 代码
obj-m := helloworld.o CURRENT_DIR :=$(shell pwd) KERNEL_DIR := /usr/src/linux-headers-$(shell uname -r) all:
$(MAKE) -C $(KERNEL_DIR) M=$(CURRENT_DIR) modules clean:
rm -rf %.o
执行make
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ make
make -C /usr/src/linux-headers-3.13.--generic M=/data1/Ryan/demo/helloworld modules
make[]: Entering directory `/usr/src/linux-headers-3.13.--generic'
Building modules, stage .
MODPOST modules
make[]: Leaving directory `/usr/src/linux-headers-3.13.--generic'
加载模块
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ sudo insmod helloworld.ko
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$
dmesg查看
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ dmesg
[178401.813566] sr :::: [sr0] Device not ready
[178401.813570] sr :::: [sr0]
[178401.813571] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[178401.813572] sr :::: [sr0]
[178401.813573] Sense Key : Not Ready [current]
[178401.813575] sr :::: [sr0]
[178401.813577] Add. Sense: Medium not present - tray closed
[178401.813579] sr :::: [sr0] CDB:
[178401.813580] Read(): 2f
[178401.813584] end_request: I/O error, dev sr0, sector
[179614.794066] helloworld: module verification failed: signature and/or required key missing - tainting kernel
[179614.794552] Hello world
[180458.268623] goodbye,cruel world
[180514.941519] Hello world
[180549.136795] goodbye,cruel world
[181244.193514] Hello world
卸载模块
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ sudo rmmod helloworld
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$
最新文章
- SELECT INTO 和 INSERT INTO区别
- 网页爬虫--scrapy入门
- oracle portlist.ini
- 域名服务器--DNS
- javascript判断NaN
- unity3d学习笔记(十九)--ngui制作3d人物头顶的头像和血条
- CI框架篇之模型篇--初识(1)
- hive 使用脚本清洗数据:时间戳转日期
- Android中倒计时代码
- 【解题报告】Math
- asp.net core mvc权限控制:分配权限
- java.lang.NoClassDefFoundError: org/apache/jsp/jsp/Container_jsp
- MVC 的 Razor引擎显示代码表达式与隐式代码表达式
- JAVA(五)反射机制/Annotation
- android linux 内核层
- JedisConnectionPool scala
- Nginx/LVS/HAProxy负载均衡软件的优缺点详解【转】
- React Native网络编程之Fetch
- ORACLE—005:创建JOB(一)
- Vim技能修炼教程(3) - 语法高亮进阶