hello.c
···
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
static int __init init_hello(void)
{
printk(KERN_ALERT "my first module test,output \"hello!\"\n");
return 0;
}
static void __exit exit_hello(void)
{
printk(KERN_DEBUG "bye bye test module!\n");
}
module_init(init_hello);
module_exit(exit_hello);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("xiaoan");
MODULE_VERSION("v0.1");
MODULE_DESCRIPTION("TEST FOR MODULE");
···
Makefile
```
obj-m := hello.o
KERNELBUILD :=/lib/modules/$(shell uname -r)/build
default:
make -C $(KERNELBUILD) M=$(shell pwd) modules
```
网友评论