-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.c
More file actions
60 lines (57 loc) · 1.56 KB
/
state.c
File metadata and controls
60 lines (57 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "headers.h"
#include "state.h"
#include "signals.h"
void removefrombg (int pid) {
jobs--;
for (int i = pid; i < jobs; i++) {
jobinfo[i].pid = jobinfo[i + 1].pid;
strcpy(jobinfo[i].name, jobinfo[i + 1].name);
}
}
void back (char * command) {
command = strtok(NULL, " ");
pid_t pid;
if (command == NULL) {
printf("No job number given\n");
}
else {
pid = atoi(command);
if (pid > jobs || pid < 1) {
printf("Invalid job number\n");
}
else {
kill(jobinfo[pid - 1].pid, SIGTTIN);
kill(jobinfo[pid - 1].pid, SIGCONT);
running.pid = processid;
strcpy(running.name, "shell");
}
}
return;
}
void fore (char * command) {
command = strtok(NULL, " ");
pid_t pid;
if (command == NULL) {
printf("No job number given\n");
}
else {
pid = atoi(command);
if (pid > jobs || pid < 1) {
printf("Invalid job number\n");
}
else {
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU,SIG_IGN);
tcsetpgrp(STDIN_FILENO, jobinfo[pid - 1].pid);
strcpy(running.name, jobinfo[pid - 1].name);
running.pid = jobinfo[pid - 1].pid;
kill(jobinfo[pid - 1].pid, SIGCONT);
removefrombg(pid - 1);
waitpid(-1, NULL, WUNTRACED);
signal(SIGTSTP, ctrlz);
tcsetpgrp(STDIN_FILENO,getpgrp());
signal(SIGTTIN,SIG_DFL);
signal(SIGTTOU,SIG_DFL);
}
}
}