Chinaunix首页 | 论坛 | 博客
  • 博客访问: 183052
  • 博文数量: 76
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 831
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-31 00:52
文章分类

全部博文(76)

文章存档

2010年(58)

2009年(18)

我的朋友

分类:

2010-02-21 18:21:16


Hello, module world ! Nice to meet you !

insert module with following command at console:
   insmod hello.ko
  insmod hello.ko whom="Mom" times=5

remove module with below command:
  rmmod hello

View the hello messages with command:
  dmesg | tail -5


#include <linux/init.h>
#include <linux/module.h>
#include <linux/stat.h>

MODULE_LICENSE("Dual BSD/GPL");

static char *whom = "world!";
static int times = 1;

module_param(whom, charp, S_IRUGO);
module_param(times, int, S_IRUGO);


static int hello_init(void)
{
    do {
        printk(KERN_ALERT "Hello, %s\n", whom);
    } while (--times);
    return 0;
}


static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel module world\n");
}


module_init(hello_init);
module_exit(hello_exit);



Makefile content:

ifneq ($(KERNELRELEASE),)
    obj-m := hello.o
else
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)
default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif






阅读(931) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~