aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-12-04 00:10:19 +0100
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-12-04 00:10:19 +0100
commit2e6aa2ab7e501e9306a8d8dda5077b875e66cc1c (patch)
tree68812419428858ff7a57c4855e565e0d99aa3eb6
parent7a5548d223a402fcdba630c0a7bb7f03ceaabf56 (diff)
third try, should work
-rw-r--r--jobs.c10
-rw-r--r--shell.c6
2 files changed, 11 insertions, 5 deletions
diff --git a/jobs.c b/jobs.c
index 6a1d797..da81500 100644
--- a/jobs.c
+++ b/jobs.c
@@ -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");
diff --git a/shell.c b/shell.c
index d3aaf63..38f6691 100644
--- a/shell.c
+++ b/shell.c
@@ -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);