ast_comparator/test/student_data/handout/shlab-handout/cases/prev_13_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;
	while((pid = waitpid(-1, &status, WUNTRACED|WNOHANG)) > 0){
		int jid = pid2jid(pid);
		if(WIFSTOPPED(status)){
			printf("Job [%d] (%d) stopped by signal %d\n", jid, pid, 20);
			struct job_t *job = getjobpid(jobs, pid);
			job->state = ST;
		}
		else if(deletejob(jobs, pid)){ 
			if(WIFSIGNALED(status)){
				printf("Job [%d] (%d) terminated by signal %d\n", jid, pid, 2);
			}
		}
	}
  return;
}
void sigchld_handler ( int sig ) { int status ; pid_t pid ; while ( ( pid = waitpid ( -1 , & status , WUNTRACED | WNOHANG ) ) > 0 ) { int jid = pid2jid ( pid ) ; if ( WIFSTOPPED ( status ) ) { printf ( " \n " , jid , pid , 20 ) ; struct job_t * job = getjobpid ( jobs , pid ) ; job -> state = ST ; } else if ( deletejob ( jobs , pid ) ) { if ( WIFSIGNALED ( status ) ) { printf ( " \n " , jid , pid , 2 ) ; } } } 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 .
/* Check with while loop with finding pid, and check signals(STOPPED, INTERRUPTED, EXITED) */ /* else, that job must be deleted in this shell. 
																			It means we don't need to check WIFEXITED(status). */