Linux內核編程:Linux2.6內核源碼解析_進程遍歷

/*   
 *File    : test.c 
 *Author  : DavidLin      
 *Date    : 2014-12-07pm      
 *Email   : [email protected] or [email protected]      
 *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 列出所以進程。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章