Shell Lab: trace07

This commit is contained in:
cyp0633 2022-05-25 12:32:33 +08:00
parent 1d8b5a6f9c
commit d43848f722
Signed by: cyp0633
GPG Key ID: E1BC508A994A5138
1 changed files with 5 additions and 2 deletions

View File

@ -347,9 +347,12 @@ void sigchld_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
if (pid != 0) // if no foreground job (PID=0), do nothing (ONLY send to foreground)
{
unix_error("sigint error"); // failed
if (kill(-pid, SIGINT) < 0) // try to send SIGINT
{
unix_error("sigint error"); // failed
}
}
return;
}