diff --git a/shlab/tsh.c b/shlab/tsh.c index c9d8f90..8ad94d1 100644 --- a/shlab/tsh.c +++ b/shlab/tsh.c @@ -325,12 +325,17 @@ void sigchld_handler(int sig) { deletejob(jobs,pid); // remove pid from job list } - if (WIFSIGNALED(status)) + if (WIFSIGNALED(status)) // SIGINT, etc. { printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status)); deletejob(jobs, pid); } - + if (WIFSTOPPED(status)) // SIGTSTP, etc. + { + printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status)); + struct job_t *job = getjobpid(jobs, pid); + job->state = ST; + } } if (pid < 0 && errno != ECHILD) { @@ -364,6 +369,14 @@ void sigint_handler(int sig) */ void sigtstp_handler(int sig) { + pid_t pid = fgpid(jobs); + if (pid != 0) + { + if (kill(-pid, SIGTSTP) < 0) + { + unix_error("sigtstp error"); + } + } return; }