首页 / 操作系统 / Linux / 重温Linux Driver基础之Hello World
Linux驱动手动加载 insmod 手动卸载 rmmod测试环境 Fedora 10Linux设备驱动第三版:参考:《linux设备驱动程序》第三版,下载在Linux公社的1号FTP服务器里,下载地址:FTP地址:ftp://www.linuxidc.com用户名:www.linuxidc.com密码:www.muu.cc在 2011年LinuxIDC.com3月《linux设备驱动程序》第三版下载方法见 http://www.linuxidc.net/thread-1187-1-1.html/*********************************************/hello.c#include <linux/init.h>
#include <linux/module.h>MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world
");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world
");
}
module_init(hello_init);
module_exit(hello_exit);#/*********************************************/makefile:obj-m := hello.oKERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)all:
$(MAKE) -C $(KERNELDIR) M=$(PWD)保存文件,使用make命令编译#make#insmod hello.ko#rmmod hello.ko在我的测试环境中,并没有直接从终端打出信息,而是在/var/log/messages中出现以下信息。至此编译运行成功。Mar 27 17:01:30 localhost kernel: Hello,world
Mar 27 17:01:36 localhost kernel: Goodbye,cruel world