ast_comparator/test/student_data/handout/shlab-handout/cases/reference_5_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, SIGTSTP, SIGTTIN or SIGTTOU 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, SIGTSTP, SIGTTIN or SIGTTOU 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 SIGTSTP SIGTTIN or SIGTTOU 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) 
{
    pid_t pid;
    int status;
    while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
        tchelper(pid);
        if (WIFEXITED(status)) {
            deletejob(job_list, pid);
        }
        else if (WIFSIGNALED(status)) {
            printf("Job [%d] (%d) terminated by signal %d\n",
                    pid2jid(pid), pid, WTERMSIG(status));
            deletejob(job_list, pid);
        }
        else if (WIFSTOPPED(status)) {
            printf("Job [%d] (%d) stopped by signal %d\n", 
                    pid2jid(pid), pid, WSTOPSIG(status));
            getjobpid(job_list, pid)->state = ST;
        }
    }
    return;
}
void sigchld_handler ( int sig ) { pid_t pid ; int status ; while ( ( pid = waitpid ( -1 , & status , WNOHANG | WUNTRACED ) ) > 0 ) { tchelper ( pid ) ; if ( WIFEXITED ( status ) ) { deletejob ( job_list , pid ) ; } else if ( WIFSIGNALED ( status ) ) { printf ( " \n " , pid2jid ( pid ) , pid , WTERMSIG ( status ) ) ; deletejob ( job_list , pid ) ; } else if ( WIFSTOPPED ( status ) ) { printf ( " \n " , pid2jid ( pid ) , pid , WSTOPSIG ( status ) ) ; getjobpid ( job_list , pid ) -> state = ST ; } } 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, SIGTSTP, SIGTTIN or SIGTTOU 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 SIGTSTP SIGTTIN or SIGTTOU signal .
/* Get the PID of the child process whose state has changed */ /* Set foreground process group ID if necessary */ /* A child process terminated normally */ /* A child process terminated due to receiving a signal */ /* A child process is currently stopped */ /* Update child process's state */