添加遍历linux系统中所有进程的驱动...

This commit is contained in:
gatieme
2016-04-05 17:04:57 +08:00
parent 2b312ecf8f
commit 866c512546
+23 -26
View File
@@ -8,7 +8,6 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
@@ -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;