內核模塊程序

hello.c

#include <linux/module.h>
#include <linux/init.h>

MODULE_LICENSE("Dual BSD/GPL");

static int __init helloworld_init(void)
{
	printk(KERN_ALERT "Hello world module init\n");
	
	return 0;
}

static void __exit helloworld_exit(void)
{
	printk(KERN_ALERT "Hello world module exit\n");
}

module_init(helloworld_init);
module_exit(helloworld_exit);

MODULE_AUTHOR("Test");
MODULE_DESCRIPTION("Hello World");
MODULE_VERSION("0.0.1");
MODULE_ALIAS("Test");


Makefile

target = hello
obj-m := $(target).o
KERNELDIR = /lib/modules/`uname -r`/build

default:
	$(MAKE) -C $(KERNELDIR) M=`pwd` modules

install:
	insmod $(target).ko

uninstall:
	rmmod $(target).ko
	
clean:
	rm -rf *.o *.mod.c *.ko *.symvers *.order *.unsigned


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章