-
Notifications
You must be signed in to change notification settings - Fork 0
/
fgbg.h
84 lines (81 loc) · 1.46 KB
/
fgbg.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef fgbg
#define fgbg
void bg(){
FILE *fp = NULL;
fp = fopen(paths,"r+");
int calc,counter,status;
counter = 0;
status = 0;
while (1 == 1){
char st[1024];
fgets(st,200,fp);
if(st[0]!=0)
counter++;
else
counter;
if(feof(fp) != 0)
break;
char store[1024] = {'\0'};
for(int i=1;st[i]!=' ';i++)
store[i-1] = st[i];
if (input[1][0]!=0)
calc=input[1][0]-48;
else
calc = 0;
int val = calculater(store,strlen(store)+1);
if (input[1][1]!=0) calc=(calc*10)+input[1][1]-48;
if(counter==calc){
kill(val,SIGCONT);
break;
}
}
if(counter == calc){
int temp = 0;
} else {
perror("Number of inputs is invalid");
}
fclose(fp);
}
void fg(){
int calc,counter,status;
counter = 0;
status = 0;
FILE *fp = NULL;
fp = fopen(paths,"r+");
while(1 == 1){
char st[1024];
fgets(st,200,fp);
if(st[0]!=0)
counter++;
else
counter;
if(feof(fp) != 0)
break;
char store[1024] = {'\0'};
for(int i=1;st[i]!=' ';i++){
store[i-1] = st[i];
}
int val = calculater(store,strlen(store)+1);
if (input[1][0]!=0)
calc=input[1][0]-48;
else
calc = 0;
if (input[1][1])
calc = ((calc*10) + input[1][1])-48;
if(counter != calc){
continue;
} else {
printf("Transferred to foreground\n");
kill(val,SIGCONT);
int ret=waitpid(val,&status,WUNTRACED);
break;
}
}
if(counter == calc){
int temp = 0;
} else {
perror("Number of inputs is invalid");
}
fclose(fp);
}
#endif