Shell Lab: trace06
This commit is contained in:
parent
adb69ffca0
commit
1d8b5a6f9c
17
shlab/tsh.c
17
shlab/tsh.c
|
@ -325,6 +325,16 @@ void sigchld_handler(int sig)
|
||||||
{
|
{
|
||||||
deletejob(jobs,pid); // remove pid from job list
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -334,8 +344,13 @@ void sigchld_handler(int sig)
|
||||||
* user types ctrl-c at the keyboard. Catch it and send it along
|
* user types ctrl-c at the keyboard. Catch it and send it along
|
||||||
* to the foreground job.
|
* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue