title: waitpid with execl used in child returns -1 with ECHILD?
body: <p>When do I need to use <code>waitpid</code> if I am using <code>execl</code> in a child process which may take time to finish?</p>
  <p>When I use <code>waitpid</code> in the parent, it tells me that the child is running as the return value from <code>waitpid</code> is 0. However, if I call <code>waitpid</code> after some time in another function, it returns -1 with <code>errno</code> set to <code>ECHILD</code>. When should I use <code>waitpid</code> if I am not sure whether the child has completed or not?</p>
  <pre><code>//pid_t Checksum_pid = fork();
  Checksum_pid = fork();
  
  if (Checksum_pid == 0)
  {
      execl(path, name, argument as needed, ,NULL);
      exit(EXIT_SUCCESS);     
  }
  else if (Checksum_pid &gt; 0)
  { 
      pid_t returnValue = waitpid(Checksum_pid, &amp;childStatus, WNOHANG);
  
      if ( returnValue &gt; 0)
      {
          if (WIFEXITED(childStatus))
          {
              printf(&quot;Exit Code: _ WEXITSTATUS(childStatus)&quot;) ;               
          }
      }
      else if ( returnValue == 0)
      {
          //Send positive response with routine status running (0x03)
          printf(&quot;Child process still running&quot;) ; 
      }
      else
      {
          if ( errno == ECHILD )
          {
               printf(&quot; Error ECHILD!!&quot;) ;
          } 
          else if ( errno == EINTR )
          {
              // other real errors handled here.
              printf(&quot; Error EINTR!!&quot;) ;
          }
          else
          {
              printf(&quot;Error EINVAL!!&quot;) ;
          }       
      }
  }
  else
  {   
      /* Fork failed. */
      printf(&quot;Fork Failed&quot;) ;
  }
  </code></pre>