遍历task_struct的子节点

时间:2015-11-24 18:49:06

标签: c kernel

下面我有代码,我试图检查是否在我当前任务的一个孩子中找到了pid(之前给出)。我已经初始化了当前的struct(current_task),理论上我正在检查它的所有子节点。我无法找到我的错误,并且编译内核需要花费太多时间(~1h)才能尝试改变很多东西。任何帮助/提示将不胜感激。

                    struct list_head children_tasks;
                    struct task_struct * child_task;

                    children_tasks = current_task->children;

                    if(children_tasks==NULL)
                            return EINVAL;

                    list_for_each(children_tasks, &current_task->children)
                    {
                            child_task = list_entry(&children_tasks, struct task_struct, sibling);
                            if(pid == child_task->pid)
                            {
                                    printk("ok");
                                    return 1;
                            }

                    }

编译器错误:

    include/linux/list.h:370:11: error: incompatible types when assigning to type 'struct list_head' from type 'struct list_head *'
  for (pos = (head)->next; prefetch(pos->next), pos != (head); \
           ^
kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
    list_for_each(children_tasks, &current_task->children)
    ^
include/linux/list.h:370:39: error: invalid type argument of '->' (have 'struct list_head')
  for (pos = (head)->next; prefetch(pos->next), pos != (head); \
                                       ^
kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
    list_for_each(children_tasks, &current_task->children)
    ^
include/linux/list.h:370:52: error: invalid operands to binary != (have 'struct list_head' and 'struct list_head *')
  for (pos = (head)->next; prefetch(pos->next), pos != (head); \
                                                    ^
kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
    list_for_each(children_tasks, &current_task->children)
    ^
include/linux/list.h:370:46: warning: left-hand operand of comma expression has no effect [-Wunused-value]
  for (pos = (head)->next; prefetch(pos->next), pos != (head); \
                                              ^
kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
    list_for_each(children_tasks, &current_task->children)
    ^
include/linux/list.h:371:19: error: invalid type argument of '->' (have 'struct list_head')
          pos = pos->next)
                   ^
kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
    list_for_each(children_tasks, &current_task->children)

1 个答案:

答案 0 :(得分:1)

宏期待指针,但children_tasks被分配为对象(struct)。您可以尝试使用&作为前缀。具体地,

list_for_each( &children_tasks, &current_task->children)

我不知道其余的是否正确,但这看起来似乎是编译错误的原因。