diff --git a/study/process/find/find_task.c b/study/process/find/find_task.c index 0a3a0db..437e8a1 100644 --- a/study/process/find/find_task.c +++ b/study/process/find/find_task.c @@ -40,7 +40,7 @@ static unsigned int PID = 1; module_param(PID, uint,0400); static int find_task_init(void) { - struct task_struct *task = NULL; + struct task_struct *task = NULL, *pTask = NULL; struct list_head *pos = NULL; char *method = NULL; @@ -54,15 +54,16 @@ static int find_task_init(void) { case 1 : method = "list_for_each"; - list_for_each(pos, &task->tasks ) + list_for_each(pos, &task->tasks) { - task = list_entry(pos, struct task_struct, tasks ); - if(task->pid == (pid_t)PID) + pTask = list_entry(pos, struct task_struct, tasks ); + if(pTask->pid == (pid_t)PID) { - printk(KERN_ALERT "%d\t%s\t%p\n", task->pid, task->comm, task); + printk(KERN_ALERT "%d\t%s\t%p\n", pTask->pid, pTask->comm, pTask); break; } } + break; case 2 : method = "for_each_process"; @@ -77,11 +78,11 @@ static int find_task_init(void) break; case 3 : method = "list_for_each_entry"; - list_for_each_entry(task, &task->tasks, tasks ) + list_for_each_entry(pTask, &task->tasks, tasks) { - if(task->pid == PID) + if(pTask->pid == PID) { - printk(KERN_ALERT "%d\t%s\t%p\n", task->pid, task->comm, task); + printk(KERN_ALERT "%d\t%s\t%p\n", pTask->pid, pTask->comm, pTask); } } } diff --git a/study/process/list/list_process.c b/study/process/list/list_process.c index 9f56703..3fade23 100644 --- a/study/process/list/list_process.c +++ b/study/process/list/list_process.c @@ -42,6 +42,14 @@ static int list_process_init(void) count++; printk(KERN_ALERT "%d\t%s\n", pTask->pid, pTask->comm); } + + // because the list of process is an double-linked circular list + // we can also list all the process from the current process + list_for_each(pos, ¤t->children) + { + pTask = list_entry(pos, struct task_struct, sibling); + printk(KERN_ALERT "%d\t%s\n", pTask->pid, pTask->comm); + } break; case 2 : method = "for_each_process";