#include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/init.h> /* Needed for the macros */ #include <linux/moduleparam.h> #include <linux/sched.h> #include <linux/string.h> #include <linux/unistd.h> int *arry[1000]; int i=0; int level=0; static char *md="-n"; module_param(md,charp,0000); MODULE_PARM_DESC(md,"parametre"); void recursion(struct task_struct *t){ level++; struct task_struct *t2; bool isFound=false; int k,l; for_each_process(t2){ if(t2->parent==t){ for(k=0;k<1000;k++){ if(!strcmp(arry[k],t2->state)){ isFound=true; break; } } if(isFound==false){ for(l=0;l<level;l++){ printk(" "); } printk(KERN_INFO "%s",t2->state); if(!strcmp(md,"-p")) printk(KERN_INFO "(%d)\n",t2->pid); else printk("\n"); arry[i]=t2->state; i++; recursion(t2); } isFound=false; } } level--; } static int __init project4_init(void) { struct task_struct *t; int j; bool isFound=false; for(j=0;j<1000;j++){ arry[j]="*******"; } for_each_process(t){ for(j=0;j<1000;j++){ if(!strcmp(arry[j],t->state)){ isFound=true; break; } } if(isFound==false){ arry[i]=t->state; i++; printk(KERN_INFO "%ld",t->state); if(!strcmp(md,"-p")) printk(KERN_INFO "(%d)\n",t->pid); else printk("\n"); recursion(t); } isFound=false; } return 0; } static void __exit project4_exit(void) { printk(KERN_INFO "Goodbye, world 2\n"); } module_init(project4_init); module_exit(project4_exit);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)