From 3c785f939eb6e0b76b2978d2acfd8b91e0a9a9f9 Mon Sep 17 00:00:00 2001 From: gatieme Date: Sun, 8 May 2016 22:32:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E9=81=8D=E5=8E=86?= =?UTF-8?q?=E6=89=80=E6=9C=89=E8=BF=9B=E7=A8=8B=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- study/process/list/list_process.c | 36 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/study/process/list/list_process.c b/study/process/list/list_process.c index c159a15..9f56703 100644 --- a/study/process/list/list_process.c +++ b/study/process/list/list_process.c @@ -21,17 +21,14 @@ module_param(METHOD, uint,0400); static int list_process_init(void) { - struct task_struct *task, *p; - struct list_head *pos; - int count; - char *method; - count = 0; /*下面这些初始化完全是为了消除编译时的警告信息*/ - p = 0; - task = 0; - pos = 0; - method = 0; - task = &init_task; + struct task_struct *task = NULL, *pTask = NULL; + struct list_head *pos = 0; + int count = 0; + char *method = NULL; + + count = 0; + task = &init_task; printk(KERN_ALERT"PID\tCOMM\n"); @@ -39,11 +36,11 @@ static int list_process_init(void) { case 1 : method = "list_for_each"; - list_for_each( pos, &task->tasks ) + list_for_each(pos, &task->tasks) { - p = list_entry( pos, struct task_struct, tasks ); + pTask = list_entry(pos, struct task_struct, tasks); count++; - printk( KERN_ALERT "%d\t%s\n", p->pid, p->comm ); + printk(KERN_ALERT "%d\t%s\n", pTask->pid, pTask->comm); } break; case 2 : @@ -51,28 +48,29 @@ static int list_process_init(void) for_each_process(task) { count++; - printk( KERN_ALERT "%d\t%s\n", task->pid, task->comm ); + printk(KERN_ALERT "%d\t%s\n", task->pid, task->comm); } break; case 3 : method = "list_for_each_entry"; - list_for_each_entry( p, &task->tasks, tasks ) + list_for_each_entry(pTask, &task->tasks, tasks) { count++; - printk( KERN_ALERT "%d\t%s\n", p->pid, p->comm ); + printk(KERN_ALERT "%d\t%s\n", pTask->pid, pTask->comm); } + break; } - printk( "The method is %s\n", method ); - printk("there are %d process in your system now...", count); + printk(KERN_ALERT "The method is %s\n", method); + printk(KERN_ALERT "there are %d process in your system now...\n", count); return 0; } static void list_process_exit(void) { - printk( KERN_ALERT "GOOD BYE!!\n"); + printk(KERN_ALERT "GOOD BYE!!\n"); }