ast_comparator/test/student_data/handout/shlab-handout/cases/31_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 stat;
  pid_t pid;
  while((pid=waitpid(fgpid(jobs), &stat, WNOHANG|WUNTRACED))>0){
	if(WIFEXITED(stat)){
		deletejob(jobs, pid);
	}else if(WIFSTOPPED(stat)){
		sigtstp_handler(10);
	}else if(WIFSIGNALED(stat)){
		sigint_handler(-1);
	}
  }
  if(errno!=ECHILD){
	unix_error("error");
  }
  return;
}
void sigchld_handler ( int sig ) { int stat ; pid_t pid ; while ( ( pid = waitpid ( fgpid ( jobs ) , & stat , WNOHANG | WUNTRACED ) ) > 0 ) { if ( WIFEXITED ( stat ) ) { deletejob ( jobs , pid ) ; } else if ( WIFSTOPPED ( stat ) ) { sigtstp_handler ( 10 ) ; } else if ( WIFSIGNALED ( stat ) ) { sigint_handler ( -1 ) ; } } 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 .
//if there is a sigchld and sigstp the shell must recognize it.
