Noga
Noga

Reputation: 145

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?

Upvotes: 5

Views: 8340

Answers (1)

Jiang
Jiang

Reputation: 501

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/

Upvotes: 5

Related Questions