ast_comparator/test/student_data/handout/shlab-handout/cases/reference_6_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(-1, &status, WNOHANG | WUNTRACED)) > 0 ) {
    if (WIFEXITED(status)) {   
        deletejob(jobs, pid);
    }
    if (WIFSIGNALED(status)) {  
        printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));
        deletejob(jobs,pid);
    }
    if (WIFSTOPPED(status)) {     
        getjobpid(jobs, pid)->state = ST;
        printf("[%d] Stopped %s\n", pid2jid(pid), jobs->cmdline);
    }
    }
    if (pid < 0 && errno != ECHILD) {
    printf("waitpid error: %s\n", strerror(errno));
    }
    return;
}
void sigchld_handler ( int sig ) { int status ; pid_t pid ; while ( ( pid = waitpid ( -1 , & status , WNOHANG | WUNTRACED ) ) > 0 ) { if ( WIFEXITED ( status ) ) { deletejob ( jobs , pid ) ; } if ( WIFSIGNALED ( status ) ) { printf ( " \n " , pid2jid ( pid ) , pid , WTERMSIG ( status ) ) ; deletejob ( jobs , pid ) ; } if ( WIFSTOPPED ( status ) ) { getjobpid ( jobs , pid ) -> state = ST ; printf ( " \n " , pid2jid ( pid ) , jobs -> cmdline ) ; } } if ( pid < 0 && errno != ECHILD ) { printf ( " \n " , strerror ( errno ) ) ; } 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 .
/*checks if child terminated normally */ /*checks if child was terminated by a signal that was not caught */ /*checks if child process that caused return is currently stopped */