#include <linux/init.h>
#include <linux/sched.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("feixiaoxing");
MODULE_DESCRIPTION("This is just a hello module!\n");
static int __init hello_init(void)
{
printk(KERN_EMERG "hello, init\n");
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_EMERG "hello, exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
PWD := $(shell pwd)
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions
endif
内核加载与卸载都需要在root用户下操作
打印输出最近一次的信息:
$ sudo dmesg | tail -f
lsmod | grep hello