ast_comparator/test/student_data/anonymized/reference_30_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;
    int pid=1;
    while(pid>0){
        pid=waitpid(-1,&status,WNOHANG|WUNTRACED);  
        if(pid>0) 
        {
            if(WIFEXITED(status)) 
                deletejob(jobs,pid);
            else {
				if(WIFSIGNALED(status)){  
					if(WTERMSIG(status)==2) 
						printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));
					deletejob(jobs,pid);
				}
				else if(WIFSTOPPED(status)){    
					getjobpid(jobs, pid)->state=ST;
					printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status));
				}
			}
        }        
    }	
}
void sigchld_handler ( int sig ) { int status ; int pid = 1 ; while ( pid > 0 ) { pid = waitpid ( -1 , & status , WNOHANG | WUNTRACED ) ; if ( pid > 0 ) { if ( WIFEXITED ( status ) ) deletejob ( jobs , pid ) ; else { if ( WIFSIGNALED ( status ) ) { if ( WTERMSIG ( status ) == 2 ) printf ( " \n " , pid2jid ( pid ) , pid , WTERMSIG ( status ) ) ; deletejob ( jobs , pid ) ; } else if ( WIFSTOPPED ( status ) ) { getjobpid ( jobs , pid ) -> state = ST ; printf ( " \n " , pid2jid ( pid ) , pid , WSTOPSIG ( status ) ) ; } } } } }
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 .
//returns pid of a child whose state changed  // check if a child's state changed // child exited normally /* child exited because a signal is not caught */ /* if signal that caused child to terminate is 2, it was terminated
											 by a different process */ /* child stopped by receipt of a signal */