ast_comparator/test/student_data/handout/shlab-handout/cases/24_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(fgpid(jobs), &status, WNOHANG | WUNTRACED)) > 0){
	if(WIFSTOPPED(status)) 		
		sigtstp_handler(SIGTSTP);
	if(WIFSIGNALED(status)){	
		sigint_handler(-1);		
	}							
	else if(WIFEXITED(status)) 
		deletejob(jobs, pid);
  }
  if(errno != ECHILD) 
	  unix_error("Waitpid error");
  return;
}
void sigchld_handler ( int sig ) { int status ; pid_t pid ; while ( ( pid = waitpid ( fgpid ( jobs ) , & status , WNOHANG | WUNTRACED ) ) > 0 ) { if ( WIFSTOPPED ( status ) ) sigtstp_handler ( SIGTSTP ) ; if ( WIFSIGNALED ( status ) ) { sigint_handler ( -1 ) ; } else if ( WIFEXITED ( status ) ) deletejob ( jobs , pid ) ; } if ( errno != ECHILD ) 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 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 .
/* To check job is terminated by signal or stopped or terminated normally */ /* If fg job is stopped, handle in sigtstp_handler() */ /* If fg job is terminated by signal, handle in sigint_handler() */ /* Child process already terminated but isn't reaped yet */ /* So give argument -1 that inform it's time to reap child to sigint handler */ /* If fg job is terminated normally, delete job from job list */ /* Waitpid error except no child */