ast_comparator/test/student_data/anonymized/reference_17_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) 
{
    int retpid = 0;
    int status = 0;
    int jid = 0;
    while ((retpid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0) {
        if (verbose) {
            printf("sigchld_handler: pid=%d\n", retpid);
        }
        jid = pid2jid(retpid);
        if(WIFSIGNALED(status)) {
            printf("Job [%d] (%d) terminated by signal %d\n", jid, retpid, WTERMSIG(status));
            deletejob(job_list, retpid);
        } else if (WIFEXITED(status)) {
            if (verbose) printf("Exited\n");
            deletejob(job_list, retpid);
        } else if (WIFSTOPPED(status)){
            printf("Job [%d] (%d) stopped by signal %d\n", jid, retpid, WSTOPSIG(status));
            getjobpid(job_list, retpid)->state = ST;
        } else {
            unix_error("unexpected result");
        }
    }
    return;
}
void sigchld_handler ( int sig ) { int retpid = 0 ; int status = 0 ; int jid = 0 ; while ( ( retpid = waitpid ( -1 , & status , WNOHANG | WUNTRACED ) ) > 0 ) { if ( verbose ) { printf ( " \n " , retpid ) ; } jid = pid2jid ( retpid ) ; if ( WIFSIGNALED ( status ) ) { printf ( " \n " , jid , retpid , WTERMSIG ( status ) ) ; deletejob ( job_list , retpid ) ; } else if ( WIFEXITED ( status ) ) { if ( verbose ) printf ( " \n " ) ; deletejob ( job_list , retpid ) ; } else if ( WIFSTOPPED ( status ) ) { printf ( " \n " , jid , retpid , WSTOPSIG ( status ) ) ; getjobpid ( job_list , retpid ) -> state = ST ; } else { unix_error ( " " ) ; } } 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 .