-
Notifications
You must be signed in to change notification settings - Fork 0
/
fg_execution.c
63 lines (59 loc) · 1.47 KB
/
fg_execution.c
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
61
62
63
#include "headers.h"
void fg_execution(char **arg, int num)
{
if (num == 2)
{
int njob = atoi(arg[1]);
int jpid;
char jname[1024];
int found = 0;
struct back *jobptr = present;
while (jobptr != NULL)
{
if (jobptr->jobnum == njob)
{
found = 1;
jpid = jobptr->backpid;
strcpy(jname, jobptr->backname);
break;
}
}
if (found == 1)
{
int jval;
kill(jpid, SIGCONT);
strcpy(fproc->fname, jname);
fproc->fpid = jpid;
struct back *jprev, *jcurr;
jcurr = present;
jprev = NULL;
while (jcurr != NULL)
{
if (jcurr->backpid == jpid)
{
if (jprev == NULL)
{
present = jcurr->next;
free(jcurr);
}
else
{
jprev->next = jcurr->next;
free(jcurr);
}
}
jprev = jcurr;
jcurr = jcurr->next;
}
waitpid(jpid, &jval, WUNTRACED);
}
else
{
fprintf(stderr, "Enter valid job number\n");
}
}
else
{
fprintf(stderr, "jobs: Incorrect syntax\n");
}
}