初学模块编程,写了个小程序测试一下:
#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是一个模板程序。
阅读(861) | 评论(0) | 转发(0) |