Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the children process list in kernel code

I want to get to the children task (process) list of a process, here is the code:

void myFunc()
{
    struct task_struct* current_task;
    struct task_struct* child_task;
    struct list_head children_list;      

    current_task = current;
    children_list = current_task->children;
    child_task = list_entry(&children_list,struct task_struct,tasks);
    printk("KERN_INFO I am parent: %d, my child is: %d \n",
            current_task->pid,child_task->pid);
}

The current pid is right, but the child pid is not correct. What am I doing wrong?

like image 244
Noga Avatar asked Apr 20 '11 10:04

Noga


1 Answers

child_task = list_entry(&children_list,struct task_struct,children);

Note, the last parameter to the list_entry should be children

btw: if you are not very familiar with list_entry, following article is a good source: http://isis.poly.edu/kulesh/stuff/src/klist/

like image 197
Jiang Avatar answered Sep 24 '22 17:09

Jiang