Chinaunix首页 | 论坛 | 博客
  • 博客访问: 95154
  • 博文数量: 17
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 210
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-13 19:51
文章分类
文章存档

2011年(1)

2010年(3)

2009年(13)

我的朋友

分类: LINUX

2010-04-08 22:08:35

初学模块编程,写了个小程序测试一下:

#include
#include
#include
#include
 
static int hello_init(void)
{   
    struct task_struct *task, *p;
    struct list_head *pos;
    task = &init_task;

    list_for_each(pos, &task->tasks) {
p = list_entry(pos, struct task_struct, tasks);
        printk(KERN_ALERT "%d--->%s---->%ld\n", p->pid, p->comm,p->state);

    }  /*-1 unrunable 0 runnable 0 stoped*/
printk(KERN_ALERT "Hello!\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "GoodBye !\n");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR( "sunfengxi" );

Makefile:

#Makefile2.6

obj-m +=kfork.o

CURRENT_PATH:=$(shell pwd)
LINUX_KERNEL := $(shell uname -r)
LINUX_KERNEL_PATH :=/usr/src/linux-headers-$(LINUX_KERNEL)

all:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
clean:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean

这个makefile是一个模板程序。





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