Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1704017
  • 博文数量: 358
  • 博客积分: 2180
  • 博客等级: 大尉
  • 技术积分: 1810
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-17 13:47
文章分类

全部博文(358)

文章存档

2016年(17)

2015年(55)

2014年(9)

2013年(67)

2012年(181)

2011年(29)

分类: LINUX

2013-06-18 15:17:14

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

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

上一篇:libnids介绍

下一篇:nmap使用手册

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