From d43848f7225850d8a1ac197b699dcb40b0fdf955 Mon Sep 17 00:00:00 2001 From: cyp0633 Date: Wed, 25 May 2022 12:32:33 +0800 Subject: [PATCH] Shell Lab: trace07 --- shlab/tsh.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shlab/tsh.c b/shlab/tsh.c index 0ef2bc6..c9d8f90 100644 --- a/shlab/tsh.c +++ b/shlab/tsh.c @@ -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; }