如何在内核代码中获取子进程列表

Nog*_*oga 5 c linked-list task linux-kernel

我想到一个进程的子任务(进程)列表,这里是代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

当前的pid是正确的,但是孩子的pid不正确.我究竟做错了什么?

Jia*_*ang 5

child_task = list_entry(&children_list,struct task_struct,children);
Run Code Online (Sandbox Code Playgroud)

注意,list_entry的最后一个参数应该是 children

顺便说一句:如果您对list_entry不是很熟悉,那么下面的文章是一个很好的来源:http: //isis.poly.edu/kulesh/stuff/src/klist/