ast_comparator/test/student_data/handout/shlab-handout/cases/2_tsh.c
/*
 * sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
 *     a child job terminates (becomes a zombie), or stops because it
 *     received a SIGSTOP or SIGTSTP signal. The handler reaps all
 *     available zombie children, but doesn't wait for any other
 *     currently running children to terminate.
 */
The kernel sends a SIGCHLD to the shell whenever
a child job terminates (becomes a zombie), or stops because it
received a SIGSTOP or SIGTSTP signal. The handler reaps all
available zombie children, but doesn't wait for any other
currently running children to terminate.
The kernel sends a SIGCHLD to the shell whenever a child job terminates ( becomes a zombie ) or stops because it received a SIGSTOP or SIGTSTP signal . The handler reaps all available zombie children but doesn ' t wait for any other currently running children to terminate .
void sigchld_handler(int sig)
{
  int status;
  pid_t pid;
  while ((pid = waitpid(fgpid(jobs), &status, WNOHANG | WUNTRACED)) > 0) {
    if (WIFEXITED(status))          
      deletejob(jobs, pid);
    else if (WIFSIGNALED(status))   
      sigint_handler(WTERMSIG(status));
    else if (WIFSTOPPED(status))    
      sigtstp_handler(WTERMSIG(status));
  }
}
void sigchld_handler ( int sig ) { int status ; pid_t pid ; while ( ( pid = waitpid ( fgpid ( jobs ) , & status , WNOHANG | WUNTRACED ) ) > 0 ) { if ( WIFEXITED ( status ) ) deletejob ( jobs , pid ) ; else if ( WIFSIGNALED ( status ) ) sigint_handler ( WTERMSIG ( status ) ) ; else if ( WIFSTOPPED ( status ) ) sigtstp_handler ( WTERMSIG ( status ) ) ; } }
sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
     a child job terminates (becomes a zombie), or stops because it
     received a SIGSTOP or SIGTSTP signal.
sigchld_handler - The kernel sends a SIGCHLD to the shell whenever a child job terminates ( becomes a zombie ) or stops because it received a SIGSTOP or SIGTSTP signal .
/* handle children according to status */ // terminated // stopped by SIGINT // stopped by SIGTSTP