书本再好也难免出错,调试通才是硬道理,运行通才是真正的硬道理。
hellomod.c
#include <linux/netdevice.h>
#include <linux/kernel.h>
#include <linux/init.h>
static int __init lkp_init(void)
{
}
static void __exit lkp_cleanup(void)
{
}
module_init(lkp_init);
module_exit(lkp_cleanup);
MODULE_LICENSE("GPL");
Makefile
obj-m += hellomod.o
doit
make -C /usr/src/kernels/2.6.18-274.7.1.el5-i686 SUBDIRS=$PWD modules
[root@localhost testNic]# ./doit
make: Entering directory `/usr/src/kernels/2.6.18-274.7.1.el5-i686'
make: Leaving directory `/usr/src/kernels/2.6.18-274.7.1.el5-i686'
[root@localhost testNic]# insmod hellomod.ko
[root@localhost testNic]# lsmod
Module
Size
Used by
hellomod
5632
0
[root@localhost testNic]# tail /var/log/messages
Nov
1 01:53:12 localhost kernel: Hello,World! from the kernel space...
[root@localhost testNic]# rmmod hellomod
[root@localhost testNic]# tail /var/log/messages
Nov
1 01:53:12 localhost kernel: Hello,World! from the kernel space...
Nov
1 01:57:14 localhost kernel: Goodbye,World! leaving kernel space...
太美妙了!