本文介绍了如何在内核代码中获取子进程列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取一个进程的子任务(进程)列表,代码如下:
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
",
current_task->pid,child_task->pid);
}
当前pid正确,但是子pid不正确.我做错了什么?
The current pid is right, but the child pid is not correct.What am I doing wrong?
推荐答案
child_task = list_entry(&children_list,struct task_struct,children);
注意,list_entry的最后一个参数应该是children
Note, the last parameter to the list_entry should be children
btw:如果您对 list_entry 不是很熟悉,以下文章是一个很好的来源:http://isis.poly.edu/kulesh/stuff/src/klist/
这篇关于如何在内核代码中获取子进程列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!