ast_comparator/test/student_data/handout/shlab-handout/cases/reference_32_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) {
pid_t pid;
int status, child_sig;
while ((pid = waitpid(-1, &status, WUNTRACED | WNOHANG)) > 0) {
printf("Handler child %d\n", (int) pid);
sigint_handler(sig);
if (
WIFSTOPPED(status)) {
sigtstp_handler(
WSTOPSIG(status));
} else if (WIFSIGNALED(status)) {
child_sig =
WTERMSIG(status);
if (child_sig == SIGINT)
sigint_handler(child_sig);
else
unix_error("sigchld_handler: uncaught signal/n");
} else
deletejob(jobs, pid); 
}
return;
}
void sigchld_handler ( int sig ) { pid_t pid ; int status , child_sig ; while ( ( pid = waitpid ( -1 , & status , WUNTRACED | WNOHANG ) ) > 0 ) { printf ( " \n " , ( int ) pid ) ; sigint_handler ( sig ) ; if ( WIFSTOPPED ( status ) ) { sigtstp_handler ( WSTOPSIG ( status ) ) ; } else if ( WIFSIGNALED ( status ) ) { child_sig = WTERMSIG ( status ) ; if ( child_sig == SIGINT ) sigint_handler ( child_sig ) ; else unix_error ( " " ) ; } else deletejob ( jobs , pid ) ; } 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 .
/* handle stop signals (this assumes all stop signals are
equivalent to SIGTSTP) */ /* 处理异常终止 */ /* remove the job under normal conditions */