From 866c51254638b7288bea0104ea76a262b439f90e Mon Sep 17 00:00:00 2001 From: gatieme Date: Tue, 5 Apr 2016 17:04:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=81=8D=E5=8E=86linux?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=B8=AD=E6=89=80=E6=9C=89=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E9=A9=B1=E5=8A=A8...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- study/process/list_process.c | 49 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/study/process/list_process.c b/study/process/list_process.c index d6bfeb7..61b537d 100644 --- a/study/process/list_process.c +++ b/study/process/list_process.c @@ -8,7 +8,6 @@ #include - #include #include @@ -18,7 +17,7 @@ //#define METHOD 2 static unsigned int METHOD = 1; -moudle_param(METHOD, uint,0400); +module_param(METHOD, uint,0400); static int list_process_init(void) { @@ -60,34 +59,32 @@ static int list_process_init(void) printk( "The method is %s\n", method ); -#if METHOD == 1 - - list_for_each( pos, &task->tasks ) + switch(METHOD) { - p = list_entry( pos, struct task_struct, tasks ); - count++; - printk( KERN_ALERT "%d\t%s\n", p->pid, p->comm ); + case 1 : + 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 ); + } + break; + case 2 : + for_each_process(task) + { + count++; + printk( KERN_ALERT "%d\t%s\n", task->pid, task->comm ); + } + break; + case 3 : + list_for_each_entry( p, &task->tasks, tasks ) + { + count++; + printk( KERN_ALERT "%d\t%s\n", p->pid, p->comm ); + } } -#elif METHOD == 2 - - for_each_process(task) - { - count++; - printk( KERN_ALERT "%d\t%s\n", task->pid, task->comm ); - } - -#elif METHOD == 3 - - list_for_each_entry( p, &task->tasks, tasks ) - { - count++; - printk( KERN_ALERT "%d\t%s\n", p->pid, p->comm ); - } - -#endif - printk("there are %d process in your system now...", count); return 0;