ast_comparator/test/student_data/handout/shlab-handout/cases/reference_12_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 (WIFSTOPPED(status))     
        {
            sigtstp_handler(20);
        }
        else if (WIFSIGNALED(status))   
        {
            sigint_handler(-2);
        }
        else if (WIFEXITED(status)) 
        {
            deletejob(jobs, pid);
        }
    }
    return;
}
void sigchld_handler ( int sig ) { int status ; pid_t pid ; while ( ( pid = waitpid ( fgpid ( jobs ) , & status , WNOHANG | WUNTRACED ) ) > 0 ) { if ( WIFSTOPPED ( status ) ) { sigtstp_handler ( 20 ) ; } else if ( WIFSIGNALED ( status ) ) { sigint_handler ( -2 ) ; } else if ( WIFEXITED ( status ) ) { deletejob ( jobs , pid ) ; } } return ; }
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 .
// Waiting for handling all of the child processes according to their status // if the child that caused the return is currently stopped in 20 sec. // if the child process terminated because of a signal that is not caught // if the child terminated normally , via a call to exit or a return