1.hello.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 0; } static int hello_exit(void) { printk(KERN_ALERT "Goodbye, cruel world\n"); return 0; } module_init(hello_init); module_exit(hello_exit); MODULE_AUTHOR("Beyond");
2.Makefile
obj-m := hello.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean