-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfg.c
More file actions
63 lines (48 loc) · 893 Bytes
/
Copy pathfg.c
File metadata and controls
63 lines (48 loc) · 893 Bytes
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<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<sys/types.h>
#include<unistd.h>
#include<fcntl.h>
#include"shell.h"
int stdoutclone;
int fg(char* args1){
if(pipe(pipedesfg)==-1){
perror("Pipe not formed\n");
return -1;
}
GLOBALSTDOUT = dup(1);
int reqpid;
dup2(pipedesfg[1], 1);
close(pipedesfg[1]);
jobscommand();
dup2(GLOBALSTDOUT, 1);
char buffer[10000];
read(pipedesfg[0], buffer, 10000);
// printf("%s\n", buffer);
for(int i=0;i<10000;i++){
if(buffer[i]=='['){
int j=i+1, flag=0;
while(args1[j-i-1]!='\0'){
if(args1[j-i-1]!=buffer[j]){
flag=1;
}
j++;
}
if(!flag){
int count=0;
while(count!=3){
if(buffer[i]==' '){
count++;
}
i++;
}
sscanf(&buffer[i], "%d", &reqpid);
}
}
}
printf("%d\n", reqpid);
kill(reqpid, SIGSTOP);
kill(reqpid, SIGCONT);
return reqpid;
}