Shell Lab: trace08

This commit is contained in:
cyp0633 2022-05-25 12:43:42 +08:00
parent d43848f722
commit ab00d9b9ce
Signed by: cyp0633
GPG Key ID: E1BC508A994A5138
1 changed files with 15 additions and 2 deletions

View File

@ -325,12 +325,17 @@ void sigchld_handler(int sig)
{ {
deletejob(jobs,pid); // remove pid from job list 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)); printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));
deletejob(jobs, pid); 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) if (pid < 0 && errno != ECHILD)
{ {
@ -364,6 +369,14 @@ void sigint_handler(int sig)
*/ */
void sigtstp_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; return;
} }