posts - 403, comments - 310, trackbacks - 0, articles - 7
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

第一次成功编译了内核模块

Posted on 2007-07-29 12:21 ZelluX 阅读(329) 评论(0)  编辑  收藏 所属分类: Linux
先抄了《Linux编程白皮书》上的代码,貌似不成功;google后改了下,编译成功。
hello.c
#include <linux/kernel.h>
#include 
<linux/module.h>

MODULE_LICENSE(
"GPL");

int init_module()
{
    printk(
"Hello, world - this is the kernel speaking\n");

    
return 0;
}

void cleanup_module()
{
    printk(
"Short is the life of a kernel module\n");
}

Makefile:
obj-m := hello.o
KERNELBUILD := /lib/modules/`uname -r`/build
default:
    make -C $(KERNELBUILD) M=$(shell pwd) modules

然后
make
sudo insmod hello.ko    // 载入模块
dmesg  // 即可看到Hello, world
sudo rmmod hello // 移除模块
dmesg // 看到移除时信息



只有注册用户登录后才能发表评论。


网站导航: