Posted on 2007-07-29 12:21 
ZelluX 阅读(342) 
评论(0)  编辑  收藏  所属分类: 
Linux 
			 
			
		 
		先抄了《Linux编程白皮书》上的代码,貌似不成功;google后改了下,编译成功。
hello.c
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
int init_module()
{
    printk("Hello, world - this is the kernel speaking\n");
    return 0;
}
void cleanup_module()
{
    printk("Short is the life of a kernel module\n");
}
Makefile:
obj-m := hello.o
KERNELBUILD := /lib/modules/`uname -r`/build
default:
    make -C $(KERNELBUILD) M=$(shell pwd) modules
然后
make
sudo insmod hello.ko    // 载入模块
dmesg  // 即可看到Hello, world
sudo rmmod hello // 移除模块
dmesg // 看到移除时信息