标签:
首先贴代码helloworld.c和Makefile
/************************************************************************* > File Name: helloworld.c > Author: hailin.ma > Mail: > Created Time: Wed 15 Jul 2015 02:39:35 PM CST ************************************************************************/ #include <linux/init.h> #include <linux/module.h> static int hello_init(void) { printk(KERN_INFO"hello world init!\n"); return 0; } static void hello_exit(void) { printk(KERN_INFO"hello world exit!\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_AUTHOR("hailin.ma <mhl2018@126.com>"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_DESCRIPTION("A simple hello world module"); MODULE_ALIAS("nothing");
Makefile
#CFLAGS = -g KVERS = /lib/modules/$(shell uname -r)/build obj-m += hello.o hello-objs:=helloworld.o all: make -C $(KVERS) M=$(PWD) modules @rm *.o clean: make -C $(KVERS) M=$(PWD) clean
insmod 加载模块
lsmod 查看已加载模块
rmmod 卸载模块
tail /var/log/messages 查看printk打印消息
标签:
原文地址:http://www.cnblogs.com/mhl2018/p/4648457.html