遍历 task_struct 的 children

Traversing the children of a task_struct

下面是我尝试检查是否在我当前任务的 children 之一中找到 pid(之前给定的)的代码。我已经初始化了当前结构 (current_task),并且我正在检查它的所有 children,理论上。我找不到我的错误,内核的编译需要太多时间(~1h)来尝试改变很多东西。任何 help/tips 将不胜感激。

                    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)

宏需要一个指针,但 children_tasks 被分配为一个对象(结构)。您可以尝试使用 & 作为前缀。具体来说,

list_for_each( &children_tasks, &current_task->children)

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