首页 > 系统服务 > 详细

零敲牛皮糖:Linux2.6内核源码解析_进程遍历

时间:2014-12-07 23:13:36      阅读:331      评论:0      收藏:0      [点我收藏+]
/*   
 *File    : test.c 
 *Author  : DavidLin      
 *Date    : 2014-12-07pm      
 *Email   : linpeng1577@163.com or linpeng1577@gmail.com      
 *world   : the city of SZ, in China      
 *Ver     : 000.000.001      
 *history :     editor      time            do      
 *          1)LinPeng       2014-12-07      created this file!      
 *          2)      
 */  

#include <linux/init.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/sched.h>

static int list_init(void)
{
    struct task_struct *task;
    
    task = NULL;
     
    for_each_process(task) {
        printk("pid = %d\n", task->pid);
    }

    return 0;
}

static void list_exit(void)
{
    printk("KERNEL MACRO: for_each_process exit\n");
}

module_init(list_init);
module_exit(list_exit);

MODULE_AUTHOR("Linpeng1577");
MODULE_DESCRIPTION("KERNEL 2.6 MACRO STUDY");
MODULE_LICENES(GPL);

这个例程的Makefile文件及测试参考之前博客:

Linux内核编程:从hello world 开始-(1)_C文件编写

Linux内核编程:从hello world 开始-(2)_Makefile文件编写

Linux内核编程:从hello world 开始-(3)_run

1.不过tail -n 3 /var/log/messages 可以改为tail -n 100 /var/log/messages;

2.ps -el 列出所以进程。

零敲牛皮糖:Linux2.6内核源码解析_进程遍历

原文:http://blog.csdn.net/linpeng12358/article/details/41792849

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!