ast_comparator/test/student_data/handout/shlab-handout/cases/42_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 olderrno = errno;
	pid_t lpid;
	sigset_t mask_all, prev_all;
	Sigfillset(&mask_all);
	while ((lpid = waitpid(-1, &status, (WNOHANG || WUNTRACED))) > 0) {
		if(WIFEXITED(status)){
			Sigprocmask(SIG_BLOCK, &mask_all, &prev_all);
			Deletejob(jobs, lpid);
			Sigprocmask(SIG_SETMASK, &prev_all, NULL);
		}
	}
	errno = olderrno;
	return;
}
void sigchld_handler ( int sig ) { int status ; int olderrno = errno ; pid_t lpid ; sigset_t mask_all , prev_all ; Sigfillset ( & mask_all ) ; while ( ( lpid = waitpid ( -1 , & status , ( WNOHANG || WUNTRACED ) ) ) > 0 ) { if ( WIFEXITED ( status ) ) { Sigprocmask ( SIG_BLOCK , & mask_all , & prev_all ) ; Deletejob ( jobs , lpid ) ; Sigprocmask ( SIG_SETMASK , & prev_all , NULL ) ; } } errno = olderrno ; 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 .
/*
		 * waitpid only take cares when child process is normally terminated.
		 * 
		 * The other case such as SIGINT, SIGTSTP is dealt inside of signal handlers
		 * And each of that handler take in charge of finishing
		 * */