title: traversing task_struct->children in linux kernel
body: <p>I am trying to traverse a task_struct's children in the linux kernel and get information from the children. I'm having problems with all the information, so let's just keep it at the getting the pid for simplicity.</p>
  
  <p>This is the relavant part of my code.</p>
  
  <pre><code>struct list_head * p;
  struct task_struct ts, *tsk;
  pid_t tmp_pid;
  INIT_LIST_HEAD(&amp;ts.children);
  
  current = tsk;
  
  list_for_each(p, &amp;(tsk-&gt;children)){
       ts = *list_entry(p, struct task_struct, children);
       tmp_pid = ts.pid;
       printk("the pid is %d\n", tmp_pid);
  }
  </code></pre>
  
  <p>I think the problem is with list_entry but I don't know how to fix it, all the examples I can find seem to be calling it the same way.</p>
  
  <p>This should print out all the child PIDs, instead I always get the same number -17.... it's on the order of 10^9 or 10^11.</p>
  
  <p>can anyone help me out here?  compiling takes about 30 minutes, so trying a log of different things isn't really an option.</p>