Chinaunix首页 | 论坛 | 博客
  • 博客访问: 521469
  • 博文数量: 122
  • 博客积分: 2024
  • 博客等级: 上尉
  • 技术积分: 1484
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-08 21:17
文章分类

全部博文(122)

文章存档

2012年(2)

2011年(25)

2010年(95)

分类: LINUX

2011-04-13 00:04:10

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

#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
阅读(1943) | 评论(0) | 转发(2) |
0

上一篇:linux小工具pstree

下一篇:linux下的内核线程

给主人留下些什么吧!~~