ast_comparator/test/student_data/handout/shlab-handout/cases/prev_8_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 stat;
    pid_t pid;
    while((pid = waitpid(-1, &stat, WNOHANG | WUNTRACED)) > 0){
        if(WIFEXITED(stat)){    
            deletejob(jobs, pid);
        }
        if(WIFSIGNALED(stat)){   by signal
            printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(stat));
            deletejob(jobs, pid);
        }
        if(WIFSTOPPED(stat)){   
            printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(stat));
            getjobpid(jobs, pid)->state = ST;
        }
    }
    if(pid < 0 && errno != ECHILD){
    }
    return;
}
void sigchld_handler ( int sig ) { int stat ; pid_t pid ; while ( ( pid = waitpid ( -1 , & stat , WNOHANG | WUNTRACED ) ) > 0 ) { if ( WIFEXITED ( stat ) ) { deletejob ( jobs , pid ) ; } if ( WIFSIGNALED ( stat ) ) { printf ( " \n " , pid2jid ( pid ) , pid , WTERMSIG ( stat ) ) ; deletejob ( jobs , pid ) ; } if ( WIFSTOPPED ( stat ) ) { printf ( " \n " , pid2jid ( pid ) , pid , WSTOPSIG ( stat ) ) ; getjobpid ( jobs , pid ) -> state = ST ; } } if ( pid < 0 && errno != ECHILD ) { } 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 .
// needed for changing job info // check child termination // check child termination by signal // check child stopped