title: Understanding SIGCHLD when the child process terminates
body: <p>I am not able to understand the output for the following program. I observed that after the child process returns, parent process is not sleeping for 3 sec before wait(). If SIGCHLD is set to default handler, then it sleeping for 3 sec, calling wait and returning as expected. What is exactly happening here ??</p>
  
  <pre><code># include &lt;unistd.h&gt;
  # include &lt;sys/types.h&gt;
  # include &lt;stdio.h&gt;
  # include &lt;sys/wait.h&gt;
  # include &lt;signal.h&gt;
  
  void handler(int sig) {
  printf("Iam in handler ...\n");
  }
  
  main() {
  
  int status;
  pid_t pid;
  
  struct sigaction act;
  //act.sa_flags=SA_NOCLDSTOP;
  act.sa_handler=handler;
  sigaction(SIGCHLD,&amp;act,NULL);
  
  if(!fork()) {
  printf("child process id is  %d\n",getpid());
   return 1;
  }  
  
  printf("xxx ...\n");
  sleep(3);
  pid = wait(&amp;status);
  printf("process terminated is %d\n",pid);
  
  }
  
  output::
  
  xxx ...
  child process id is  2445
  Iam in handler ...
  process terminated is 2445
  </code></pre>