现在的位置: 首页 > 综合 > 正文

hello world module

2014年09月05日 ⁄ 综合 ⁄ 共 954字 ⁄ 字号 评论关闭

hello.c

//////////////////////////////////////////////////////////////////////////

#include <linux/init.h>

#include <linux/module.h>

 

MODULE_LICENSE ("Dual BSD/GPL");

 

static int hello_init (void)

{

    printk (KERN_ALERT "hello to module");

 

    return 0;

}

 

static void hello_exit (void)

{

    printk (KERN_ALERT "goodbye hello to module");

}

 

module_init (hello_init);

module_exit (hello_exit);

 

Makefile

//////////////////////////////////////////////////////////////////////

obj-m:=hello.o

 

make command

///////////////////////////////////////////////////////////////////////

make -C /usr/src/linux-headers-2.6.28-18-generic/ M=`pwd` modules

 

install the module

////////////////////////////////////////////////////////////////////////

sudo insmod ./hello.ko

 

trace the hello module

////////////////////////////////////////////////////////////////////////

cat /proc/modules  | grep hello

 

see : hello 9344 0 - Live 0xf7e01000

 

remove the module

////////////////////////////////////////////////////////////////////////

sudo rmmod hello

抱歉!评论已关闭.