ast_comparator/test/student_data/handout/shlab-handout/cases/58_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 olderrno=errno;
  int status;
  pid_t pid;
  if ((pid=waitpid(-1, &status, WUNTRACED | WNOHANG))<0)
    unix_error("signal error");
  if (pid!=0 && WEXITSTATUS(status)==0) {
    struct job_t *job;
    if ((job=getjobpid(jobs, pid))==NULL)
      app_error("sigchld: get job");
    if (deletejob(jobs, pid)==0)
      app_error("delete job");
  }
  errno=olderrno;
  return;
}
void sigchld_handler ( int sig ) { int olderrno = errno ; int status ; pid_t pid ; if ( ( pid = waitpid ( -1 , & status , WUNTRACED | WNOHANG ) ) < 0 ) unix_error ( " " ) ; if ( pid != 0 && WEXITSTATUS ( status ) == 0 ) { struct job_t * job ; if ( ( job = getjobpid ( jobs , pid ) ) == NULL ) app_error ( " " ) ; if ( deletejob ( jobs , pid ) == 0 ) app_error ( " " ) ; } 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 .
/* checking for childs to reap */ /* deleting child process from jobs list if it has been reaped */