How can I get the children process list in kernel code

与世无争的帅哥 提交于 2019-12-21 17:23:20

问题


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?


回答1:


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/



来源:https://stackoverflow.com/questions/5728592/how-can-i-get-the-children-process-list-in-kernel-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!