ubuntu 10.04 下驱动程序的hello word

# 本机内核版本为: 2.6.32-41-generic

/* hello.c */  
#include <linux/module.h>  
#include <linux/init.h>  
      
MODULE_LICENSE("GPL");  
MODULE_AUTHOR("root");  
MODULE_DESCRIPTION("Hello world module");  
      
static int __init hello_init(void)  
{  
        printk(KERN_NOTICE "hello world!\n");  
        return 0;  
}
 
static void __exit hello_exit(void)  
{  
        printk(KERN_NOTICE "hello exit!\n");  
}  
      
module_init(hello_init);  
module_exit(hello_exit); 

 

############# makefile ################
 
ifneq ($(KERNELRELEASE),)   
    obj-m :=hello.o   
else
 
KDIR:= /lib/modules/2.6.32-41-generic/build
all:   
    make -C $(KDIR) M=$(PWD) modules  
clean:   
    rm -f *.ko *.o *.mod.o *.mod.c .symvers   
endif

###################加载模块##############

insmod hello.ko

##################查看模块#############
lsmod  | grep hello

#################移除模块###############

rmmod hello.ko

################查看模块打印消息#########

dmesg -c

posted on 2012-06-10 10:56  shang_qd  阅读(173)  评论(0编辑  收藏  举报

导航