title: Reaping zombie process - child
body: <p>I am taking command line arguments to main from parent to child and counting them and printing. My question is that i am not sure that i am reaping the child? dont i just need an exit 0
  or do i need to call fork again?</p>
  
  <pre><code>#include &lt;sys/wait.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;string.h&gt;
  
  int main(int argc, char *argv[])
  {
  
  int length = 0;
  int i, n;
  
  int     fdest[2];          // for pipe
  pid_t   pid;              //process IDs
  char    buffer[BUFSIZ];
  
  
  if ((pid = fork()) &lt; 0)  /* attempt to create child / parent process */
  
  {
      printf("fork error");
  } 
  
  if (pipe(fdest) &lt; 0)          /* attempt to create pipe */
      printf("pipe error");
  
  /* parent process */
  else if (pid &gt; 0) {      
      close(fdest[0]);
  
      for(i = 1; i &lt; argc; i++)    /* write to pipe */
      {
          write(fdest[1], argv[i], strlen(argv[1]));
      }
  
  } else {   
  
      /* child Process */
      close(fdest[1]);
  
      for(i = 1; i &lt; argc; i++)
      {
          length +=( strlen(argv[i])); /* get length of arguments */
      }
  
      n = read(fdest[0], buffer, length);
      printf("\nchild: counted %d characters\n", n);
  
  }
  exit(0);
  }
  </code></pre>