Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4273063
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类:

2011-04-13 14:57:54

/*****************************************
*功能:利用进程链表遍历当前系统中的所有进程
*同时可以打印出进程的相关信息
*
* ***************************************/

#include
#include
#include
#include


static int list_init(void)
{
        struct task_struct *task, *p;
        struct list_head *pos;

        int count = 0;
        task = &init_task;

        printk(KERN_ALERT"PID\tCOMM\n");
        list_for_each( pos, &task->tasks ) {
                p = list_entry( pos, struct task_struct, tasks );
                count++;
                printk( KERN_ALERT "%d\t%s\n", p->pid, p->comm );
        }
        printk("系统当前共 %d 个进程!!", count);
        return 0;
}
static void list_exit(void)
{
        printk( KERN_ALERT "GOOD BYE!!\n");
}
MODULE_AUTHOR("Along");
MODULE_LICENSE("GPL");
module_init(list_init);
module_exit(list_exit);[/code]我的Makefile:[code]obj-m := list.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd) 
all:
        make -C $(KERNELDIR) M=$(PWD) modules
clean:
        make -C (KERNELDIR) M=$(PWD) clean
阅读(874) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~