linux kernel 学习 ----构造和运行模块
2014-05-19 00:13
141 查看
1第一个模块----hello world!
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk(KERNEL_ALERT“hello,world\n”);
return 0;
}
static int hello_exit(void)
{
printk(KERNEL_ALERT"BYE BYE!");
return 0;
}
module_init(hello_init); //模块装载到内核时被调用
module_exit(hello_exit); //模块从内核卸载时被调用
2Makefile实例
ifneq ($(KERNELRELEASE),)
obj-m := hello.o //说明有一个模块需要从hello.中构造,而从该目标文件中构造的模块名称为hello.ko
else
KERNELDIR ?=/lib/modules/$(shell uname -r)/build //对应内核的源代码树
PWD :=$(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
@echo “success!”
endif
3、装载和卸载模块
insmod hello.ko
rm hello or rm hello.ko
显示内核模块
lsmod
![](http://img.blog.csdn.net/20140519001209656?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3VwZW5tYW5fbXdn/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
ls /proc/module
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk(KERNEL_ALERT“hello,world\n”);
return 0;
}
static int hello_exit(void)
{
printk(KERNEL_ALERT"BYE BYE!");
return 0;
}
module_init(hello_init); //模块装载到内核时被调用
module_exit(hello_exit); //模块从内核卸载时被调用
2Makefile实例
ifneq ($(KERNELRELEASE),)
obj-m := hello.o //说明有一个模块需要从hello.中构造,而从该目标文件中构造的模块名称为hello.ko
else
KERNELDIR ?=/lib/modules/$(shell uname -r)/build //对应内核的源代码树
PWD :=$(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
@echo “success!”
endif
3、装载和卸载模块
insmod hello.ko
rm hello or rm hello.ko
显示内核模块
lsmod
ls /proc/module
相关文章推荐
- Linux设备驱动程序学习(2)-构造和运行模块
- Linux设备驱动开发学习(3):构造和运行模块
- Linxu设备驱动学习之构造和运行模块(菜鸟篇)~~~
- linux设备驱动学习(2) 构造和运行模块
- 第二章 构造和运行模块——note
- 02 构造和运行模块
- Linux device drives chapter 2(构造和运行模块)
- 构造和运行模块
- 01-构造和运行模块
- linux驱动学习2:运行hello模块
- LDD读书实验笔记——构造和运行模块
- magento 学习笔记-模块运行流程
- linux 设备驱动程序 (2) —— 构造和运行模块
- hadoop学习笔记1----构造模块与集群安装ssh与启动Hadoop
- 《Linux Device Drivers》第二章 构造和运行模块——note
- 构造和运行模块
- 《Linux设备驱动程序》前两章 设备驱动程序 即构造和运行模块:读书笔记
- linux设备驱动编程-初探(2)--在内核中构造和运行模块
- LDD3笔记:第二章 构造和运行模块
- 【Linux 驱动】第二章 构造和运行模块