title: Traversing the children of a task_struct
body: <p>Below I have the code where Im trying to check if a pid( given before) is found in one of the childrens of my current task. I have already initialized the current struct (current_task) and I am checking all its children, in theory. I cant find my mistake and the compiling of the kernel takes too much (~1h) to try and change many things. Any help/tips would be appreciated.                        </p>
  
  <pre><code>                    struct list_head children_tasks;
                      struct task_struct * child_task;
  
                      children_tasks = current_task-&gt;children;
  
                      if(children_tasks==NULL)
                              return EINVAL;
  
                      list_for_each(children_tasks, &amp;current_task-&gt;children)
                      {
                              child_task = list_entry(&amp;children_tasks, struct task_struct, sibling);
                              if(pid == child_task-&gt;pid)
                              {
                                      printk("ok");
                                      return 1;
                              }
  
                      }
  </code></pre>
  
  <p>Compiler Errors:</p>
  
  <pre><code>    include/linux/list.h:370:11: error: incompatible types when assigning to type 'struct list_head' from type 'struct list_head *'
    for (pos = (head)-&gt;next; prefetch(pos-&gt;next), pos != (head); \
             ^
  kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
      list_for_each(children_tasks, &amp;current_task-&gt;children)
      ^
  include/linux/list.h:370:39: error: invalid type argument of '-&gt;' (have 'struct list_head')
    for (pos = (head)-&gt;next; prefetch(pos-&gt;next), pos != (head); \
                                         ^
  kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
      list_for_each(children_tasks, &amp;current_task-&gt;children)
      ^
  include/linux/list.h:370:52: error: invalid operands to binary != (have 'struct list_head' and 'struct list_head *')
    for (pos = (head)-&gt;next; prefetch(pos-&gt;next), pos != (head); \
                                                      ^
  kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
      list_for_each(children_tasks, &amp;current_task-&gt;children)
      ^
  include/linux/list.h:370:46: warning: left-hand operand of comma expression has no effect [-Wunused-value]
    for (pos = (head)-&gt;next; prefetch(pos-&gt;next), pos != (head); \
                                                ^
  kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
      list_for_each(children_tasks, &amp;current_task-&gt;children)
      ^
  include/linux/list.h:371:19: error: invalid type argument of '-&gt;' (have 'struct list_head')
            pos = pos-&gt;next)
                     ^
  kernel/set_period_parameters.c:47:4: note: in expansion of macro 'list_for_each'
      list_for_each(children_tasks, &amp;current_task-&gt;children)
  </code></pre>