模块化编程
编译加载查看命令
make
编译lsmod
显示模块insmod/rmmod
安装/卸载模块dmesg
打印log信息dmesg -c
清除当前的log
试验环境
ubuntu 虚拟机
实例
#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("NEONAN");
static int hello_init(void)
{
printk("hello_init\n");
return 0;
}
static void hello_exit(void)
{
printk("hello_exit\n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
ifneq ($(KERNELRELEASE),)
obj-m:=hello.o
else
KDIR :=/lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.o *.symvers *.cmd *.mod.c *.order
endif