ast_comparator/test/student_data/handout/shlab-handout/cases/42_tsh.c
/*
 * sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever
 *     the user types ctrl-z at the keyboard. Catch it and suspend the
 *     foreground job by sending it a SIGTSTP.
 */
The kernel sends a SIGTSTP to the shell whenever
the user types ctrl-z at the keyboard. Catch it and suspend the
foreground job by sending it a SIGTSTP.
The kernel sends a SIGTSTP to the shell whenever the user types ctrl - z at the keyboard . Catch it and suspend the foreground job by sending it a SIGTSTP .
void sigtstp_handler(int sig)
{
	int jobidx;
	pid_t fpid;
	sigset_t prev_all, mask_one, mask_all;
	struct job_t *stpjob;
	Sigaddset(&mask_one, SIGCHLD);
	Sigfillset(&mask_all);
	if((fpid = fgpid(jobs)) == 0) {
		printf("There is no foreground job\n");
		return;		
	}
	Kill(-fpid, SIGTSTP);
	jobidx = pid2jid(fpid);
	Sigprocmask(SIG_BLOCK, &mask_all, &prev_all);
	if((stpjob = getjobpid(jobs, fpid)) == 0) {
		printf("no such job\n");
		exit(0);
	}
	stpjob->state = ST; 	
	Sigprocmask(SIG_SETMASK, &prev_all, NULL);
	printf("Job [%d] (%d) stopped by signal 20\n", jobidx, fpid);
	return;
}
void sigtstp_handler ( int sig ) { int jobidx ; pid_t fpid ; sigset_t prev_all , mask_one , mask_all ; struct job_t * stpjob ; Sigaddset ( & mask_one , SIGCHLD ) ; Sigfillset ( & mask_all ) ; if ( ( fpid = fgpid ( jobs ) ) == 0 ) { printf ( " \n " ) ; return ; } Kill ( - fpid , SIGTSTP ) ; jobidx = pid2jid ( fpid ) ; Sigprocmask ( SIG_BLOCK , & mask_all , & prev_all ) ; if ( ( stpjob = getjobpid ( jobs , fpid ) ) == 0 ) { printf ( " \n " ) ; exit ( 0 ) ; } stpjob -> state = ST ; Sigprocmask ( SIG_SETMASK , & prev_all , NULL ) ; printf ( " \n " , jobidx , fpid ) ; return ; }
sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever
     the user types ctrl-z at the keyboard.
sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever the user types ctrl - z at the keyboard .
/* Send SIGTSTP to foreground job process */ /* change the job structures with stop state */