【发布时间】:2011-04-20 10:03:34
【问题描述】:
我想获取一个进程的子任务(进程)列表,代码如下:
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);
}
当前 pid 正确,但子 pid 不正确。 我做错了什么?
【问题讨论】:
-
我对linux-kernel一无所知,但我觉得应该是
struct list_head *children_list和后来的children_list = &current_task->children。 -
谢谢,但
current_task->children返回list_head而不是list_head* -
我知道它已经过去了 5 年,但 @king_nak 的意思是你不应该复制结构,而是使用指向它的指针。所以你把'&'放在 current_task->children 之前。
标签: c linux-kernel linked-list task