title: How can I handle SIGCHLD?
body: <p>I need to handle <code>SIGCHLD</code> properly. How can I use it with my existing code? at the moment I cant wait for the child process unless I use <code>0</code> instead of <code>WNOHANG|WUNTRACED</code>.  </p>
  
  <pre><code>status = 0; 
  pid_t child, endID;
  
  if(amp == 1)
          signal( SIGCHLD, SIG_IGN ); 
  
  child = fork(); 
  
  if (child  &lt;  0) {    
          perror("fork() error\n");
          exit(EXIT_FAILURE);
  
  } else if (child == 0) { 
          // do sth here
          perror("error\n");
  
  } else { 
          //sleep(1)
  </code></pre>
  
  <p>If I remove <code>sleep</code> then parent is executed 1st.. why?</p>