HelloWord.c文件内容
#include<linux/init.h>
#include<linux/module.h>
#include<linux/sched.h>
MODULE_LICENSE("Bual BSD/GPL");
static int hello_init(void)
{
printk("helloword init\r");
printk(KERN_INFO "The processer is \"%s\" (pid %i)\n",current->comm,current->pid);
printk("\n");
return 0;
}
static void hello_exit(void)
{
printk("helloword exit\r");
printk("\n");
}
module_init(hello_init);
module_exit(hello_exit);
编译的Makefile文件内容
#sample driver module
obj-m := HelloWord.o
KDIR = /usr/src/linux-headers-5.0.0-27-generic
all:
$(MAKE) -C $(KDIR) M=$(PWD)
.PHONY:clean
clean:
rm -f *.mod.c *.mod.o *.ko *.o *.tmp_versions
编译命令
make
安装模块命令
insmode xxx.ko
卸载模块命令
rmmode xxx.ko