File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ obj-m += test.o
2
+ all :
3
+ make -C /lib/modules/$(shell uname -r) /build M=$(PWD ) modules
4
+ clean :
5
+ make -C /lib/modules/$(shell uname -r) /build M=$(PWD ) clean
Original file line number Diff line number Diff line change
1
+ 环境:
2
+ Ubuntu 20.04 server
3
+
4
+ 编译命令:
5
+ make
6
+
7
+ 加载模块命令:
8
+ insmod test.ko
9
+
10
+ 卸载模块命令:
11
+ rmmond test.ko
12
+
13
+ 查询模块打印日志:
14
+ dmesg
Original file line number Diff line number Diff line change
1
+ #include <linux/init.h>
2
+ #include <linux/module.h>
3
+ #include <linux/kernel.h>
4
+
5
+ MODULE_LICENSE ("GPL" );
6
+ MODULE_AUTHOR ("test" );
7
+ MODULE_DESCRIPTION ("A simple example Linux module." );
8
+ MODULE_VERSION ("0.1" );
9
+
10
+ static int __init test_init (void ) {
11
+ printk (KERN_INFO "Hello, World!\n" );
12
+ return 0 ;
13
+ }
14
+ static void __exit test_exit (void ) {
15
+ printk (KERN_INFO "Goodbye, World!\n" );
16
+ }
17
+
18
+ module_init (test_init );
19
+ module_exit (test_exit );
You can’t perform that action at this time.
0 commit comments