ast_comparator/test/student_data/handout/shlab-handout/cases/reference_21_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=waitpid(-1,&status, WNOHANG|WUNTRACED);
    struct job_t *jobIds;
    jobIds=getjobpid(jobs,pid);
    if (WIFSIGNALED(status))
    {
        printf("Job [%d] (%d)  terminated by signal 2\n",jobIds->jid,jobIds->pid);
        deletejob(jobs,pid);
    }
    else if (WIFSTOPPED(status))
    {
        printf("Job [%d] (%d)  stopped by signal 20\n",jobIds->jid,jobIds->pid);
        jobIds->state = ST;
    }
    else if (WIFEXITED(status))
    {  
        deletejob(jobs, pid);  
    }
    return;
}
void sigchld_handler ( int sig ) { int status ; pid_t pid = waitpid ( -1 , & status , WNOHANG | WUNTRACED ) ; struct job_t * jobIds ; jobIds = getjobpid ( jobs , pid ) ; if ( WIFSIGNALED ( status ) ) { printf ( " \n " , jobIds -> jid , jobIds -> pid ) ; deletejob ( jobs , pid ) ; } else if ( WIFSTOPPED ( status ) ) { printf ( " \n " , jobIds -> jid , jobIds -> pid ) ; jobIds -> state = ST ; } 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 all the children to finish their processes // Checking the signal of the child // If the process was terminated // If the process was stopped // If the process was exited