Shell Lab: trace06

This commit is contained in:
cyp0633 2022-05-25 10:44:33 +08:00
parent adb69ffca0
commit 1d8b5a6f9c
Signed by: cyp0633
GPG Key ID: E1BC508A994A5138
1 changed files with 16 additions and 1 deletions

View File

@ -325,6 +325,16 @@ void sigchld_handler(int sig)
{
deletejob(jobs,pid); // remove pid from job list
}
if (WIFSIGNALED(status))
{
printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));
deletejob(jobs, pid);
}
}
if (pid < 0 && errno != ECHILD)
{
unix_error("waitpid error");
}
return;
}
@ -334,8 +344,13 @@ void sigchld_handler(int sig)
* user types ctrl-c at the keyboard. Catch it and send it along
* to the foreground job.
*/
void sigint_handler(int sig)
void sigint_handler(int sig)
{
pid_t pid = fgpid(jobs); // get pid of foreground job
if (kill(-pid, SIGINT) < 0) // try to send SIGINT
{
unix_error("sigint error"); // failed
}
return;
}