模块与系统调用
编写printname.c 函数
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static char *name="dhr";
static int __init name_init(void)
{
printk("==Hello World==
");
printk("==Hello %s==
",name);
return 0;
}
static void __exit name_exit(void)
{
printk(KERN_INFO"Name module exit
");
}
module_init(name_init);
module_exit(name_exit);
module_param(name,charp,S_IRUGO);
~
编写Makefile文件
obj-m:=module3.o
CURRENT_PATH:=$(shell pwd)
LINUX_KERNEL_PATH:=/usr/src/linux-3.16.76
all:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
clean:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
~
编译并安装模块
$sudo make
$sudo insmod printname.ko
$dmesg
结果如下: