ast_comparator/test/student_data/handout/shlab-handout/cases/reference_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)
{
    pid_t pid;
    int status;
    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("Job [%d] (%d) stopped by signal %d\n",pid2jid(pid),pid,WSTOPSIG(status));
        }
    }
    if(pid < 0 && errno != ECHILD)
    printf("waitpid error: %s\n", strerror(errno));
    return;
}
void sigchld_handler ( int sig ) { pid_t pid ; int status ; 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 ) , pid , WSTOPSIG ( status ) ) ; } } 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 .
/*process is exited in normal way*/ /*process is terminated by a signal*/ /*process is stop because of a signal*/