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; }