title: os161 parent and child thread pid
body: <p>Is anyone familiar with <a href="http://www.eecs.harvard.edu/~syrah/os161/" rel="nofollow">os/161</a> and can answer a few questions for me?</p>
  
  <p>How exactly does child pid, parent pid works. </p>
  
  <p>I know that when you call <code>thread_fork()</code> you are creating another thread base on the current thread, the new thread should have a unique id for himself and a different file descriptor table.  While <code>sys_fork</code> create a child from <code>curthread</code>, the child is the same as the parent besides the pid. But I am confused in how pid and parent pid works.</p>
  
  <p>This is my interpretation of the process table. There is only one process table for the whole system. For now I have <code>parent_pid</code> and <code>my_pid</code> for every thread.<br>
  -A parent thread can have multiple child, (by keep calling <code>sys_fork</code>).<br>
  -A child can only have one parent.<br>
  -Whenever <code>sys_fork</code> is called, a child is created and the <code>parent_pid</code> for this child is set to the pid of the thread who created this child.<br>
  -pid of 1 is for the boot/menu thread.</p>
  
  <p>Am I even on the right track in understanding how process table works?</p>
  
  <p>One last question:
  For <code>sys_waitpid()</code>: Only parent can use <code>waitpid</code>? and they can only wait on their childs? Can a child use <code>waitpid</code> on a parent (or would this result in deadlock)?</p>
  
  <p>I been searching around with Google, but I find so many contradictions, up till now I still can't find a clear answer to my questions.</p>