title: Trouble using fork() to create two child processes in C (in Debian)
body: <p>Trying to split a parent process into two children.  The first will calculate factorials of a given number.  The second will just say <code>I'm child 2!</code> When that's done, the first child will output the time taken to calculate the factorials.  Getting the first child to split and do its job is working just fine.  However, I can't see to get the second child to do anything.  Any idea what I'm doing wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  //#include &lt;/sts/types.h&gt;
  #include &lt;unistd.h&gt;
  
  //prototypes
  int rfact(int n);
  int temp = 0;
  
  main()
  {
      int n = 0;
      long i = 0;
      double result = 0.0;
      clock_t t;
      printf("Enter a value for n: ");
      scanf("%i", &amp;n);
  
      pid_t pID = fork();
      if (pID ==0)//child
      {
          //get current time
          t = clock();
  
          //process factorial 2 million times
          for(i=0; i&lt;2000000; i++)
          {
              rfact(n);
          }
  
          //get total time spent in the loop
          result = ((double)(clock() - t))/CLOCKS_PER_SEC;
  
          //print result
          printf("runtime=%.2f seconds\n", result);
      }
      else if(pID &lt; 0)
      {
          printf("fork() has failed");
      }
      else //parent
      {
          //second fork for child 2
          pid_t pID2 = fork();
          if (pID2 == 0)
          {
              execl("child2.o","child2", 20, NULL);
          }
          else if (pID2 &lt; 0)
          {
              printf("fork() has failed");
          }
          else
          {
              waitpid(0);
          }
          waitpid(0);
      }
  }
  
  //factorial calculation
  int rfact(int n)
  {
      if (n&lt;=0)
      {
          return 1;
      }
      return n * rfact(n-1);
  }
  </code></pre>
  
  <p>Here's child2.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void main()
  {
      printf("I'm child 2!");
  }
  </code></pre>
  
  <p>Alright, so, I was having problems with eclipse.  I dropped it and recompiled both .c files.  I used execl to point to child2.o, but it's still not doing anything</p>