title: Binary Process Tree with fork()
body: <p>My first project for my OS class is to create a process tree using <code>fork()</code> that has a depth that the user specifies at the command line. Each leaf level node needs to sort data and pass it back to its parent using named-pipes (FIFOs).</p>
  
  <p>I can create an N-depth tree with <code>fork()</code>, each process having 2 children. What I can’t figure out is how to pass a FIFO to each child all the way down the tree and then have this <em>process</em> perform a sort on certain data in the FIFO <em>and then</em> also pass it back up the tree to the top.</p>
  
  <p>Here is the pseudo-code of what I have so far for building the tree:</p>
  
  <pre><code>void CreateTree(int level)
  {
      if level = 0 return
  
      int left_child = fork();
      if(left_child != 0)        //we are the parent
      {
          int right_child = fork();
          if(right_child == 0)
              CreateTree(level - 1);
      }
      else
      {
          CreateTree(level-1);
      }
  }
  </code></pre>
  
  <p>So how do I grab each process individually to do work with them?</p>