title: Calculating total number of processes in fork() code
body: <p>I am trying to determine how many total number of processes there are in the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main() {  
  
  int i = 1;
  
     if (fork ()) //parent process will return PID of child.
          i++;
     else if (fork()) //child process (becomes parent)
              i--;
         else //grandchild process returns 0
              i++;
  
   printf("%d\n", i);
  }
  </code></pre>
  
  <p>Generally, the formula for total # of processes is 2^n where n is the number of fork system calls.  I am confused because this sample involves if/else conditional statements.</p>
  
  <p>I am getting 4 processes in total.  (2 processes from the <strong>if(fork())</strong> statement and 2 processes from the <strong>elseif(fork())</strong> statement).  Can someone confirm if this is correct or not? And if not, can you please guide me in the right direction / explain how to calculate the number of processes.  This is something I'm having quite a bit of trouble determining.</p>
  
  <p>Thank you all.</p>