diff options
author | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-12-04 00:10:19 +0100 |
---|---|---|
committer | Franciszek Malinka <franciszek.malinka@gmail.com> | 2021-12-04 00:10:19 +0100 |
commit | 2e6aa2ab7e501e9306a8d8dda5077b875e66cc1c (patch) | |
tree | 68812419428858ff7a57c4855e565e0d99aa3eb6 | |
parent | 7a5548d223a402fcdba630c0a7bb7f03ceaabf56 (diff) |
third try, should work
-rw-r--r-- | jobs.c | 10 | ||||
-rw-r--r-- | shell.c | 6 |
2 files changed, 11 insertions, 5 deletions
@@ -225,7 +225,10 @@ bool resumejob(int j, int bg, sigset_t *mask) { return false; printf("[%d] continue \'%s\'\n", j, job->command); - Kill(job->pgid, SIGCONT); + if (bg == FG) { + setfgpgrp(job->pgid); + } + Kill(-job->pgid, SIGCONT); /* MY-TODO: what if there is some job in the foreground? * I think it shouldn't happen, but what if? */ if (bg == FG) { @@ -252,8 +255,8 @@ bool killjob(int j) { if (jobs[j].pgid == 0) return false; /* If job is stopped, then it won't handle the SIGTERM */ - Kill(jobs[j].pgid, SIGCONT); - Kill(jobs[j].pgid, SIGTERM); + Kill(-jobs[j].pgid, SIGTERM); + Kill(-jobs[j].pgid, SIGCONT); #endif /* !STUDENT */ return true; @@ -316,7 +319,6 @@ int monitorjob(sigset_t *mask) { job_t *j = &jobs[FG]; Tcsetpgrp(tty_fd, j->pgid); - Tcsetattr(tty_fd, TCSADRAIN, &j->tmodes); do { // msg("> Suspedning\n"); @@ -149,8 +149,12 @@ static pid_t do_stage(pid_t pgid, sigset_t *mask, int input, int output, MaybeClose(&input); MaybeClose(&output); } else { /* job */ - if (pgid == 0) + if (pgid == 0) { pgid = getpid(); + if (bg == FG) { + setfgpgrp(getpid()); + } + } Setpgid(pid, pgid); Signal(SIGINT, SIG_DFL); Signal(SIGTSTP, SIG_DFL); |