【linux】——helloworld模块编写与测试
来源:互联网 发布:思途旅游网站源码 编辑:程序博客网 时间:2024/06/10 21:22
将RedHat Linux 9.0的内核升级到2.6.18后,就开始学习驱动的编写了。
在ldd3中,有一个helloworld模块,C程序代码如下:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world/n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world/n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile文件内容如下:
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
然后make
执行insmod ./hello.ko或者insmod hello.ko
就将helloworld模块加载,但是在终端上并不会打印出消息(不知道?!?!)
然后用lsmod查看hello模块是否加载好
再执行
rmmod hello.ko
卸载helloworld模块,再用lsmod查看是否卸载hello模块
再执行dmesg |tail -8查看printk的打印消息
- 【linux】——helloworld模块编写与测试
- 内核模块编写helloworld
- ubuntu helloworld 内核模块编写
- linux之helloworld编写
- Linux 内核模块 helloworld
- Linux 内核模块编写与安装
- Linux内核模块编程-HelloWorld
- 字符设备驱动模块与测试代码编写(转)
- 编写简单的内核模块——Linux操作系统原理与应用(陈莉君第2版13页)
- 编写Linux内核模块
- linux内核模块编写
- 编写Linux内核模块
- linux 内核模块编写
- Linux编写驱动模块
- linux下编写汇编的Helloworld
- linux下编写汇编的Helloworld
- linux 模块编程的简单示例 helloworld
- linux 模块驱动开发第一弹 helloworld
- java包的应用
- java.util.Arrays.asList 的小问题
- 关于流加密
- 传智播客android系统开发全程笔记
- servlet的应用 ServletTest1 例子
- 【linux】——helloworld模块编写与测试
- MIS第一章学习认知
- oracle 九九乘法表的应用pl/sql块的实例(笨小孩)
- Swing+数据库连接
- 大家围观围观
- 我的c++
- 多表查询优化1
- 原来幸福可以这么简单
- 20110502