-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfg.c
More file actions
46 lines (44 loc) · 1020 Bytes
/
fg.c
File metadata and controls
46 lines (44 loc) · 1020 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
#include"headers.h"
int func_fg(char **a){
strcpy(current_fg, a[0]);
pid_t pid;
pid = fork();
int stat;
if(pid < 0){
perror("Error");
_exit(1);
}
else if(pid == 0){
if(execvp(a[0], a) == -1){
printf("Error : Command not found");
}
exit(0);
}
else{
int status;
current_fg_pid = pid;
fg_pid = pid;
czz = 0;
waitpid(pid, &status, WUNTRACED);
}
return 0;
}
void fg(int no){
int status, pid;
if(no > job_no){
printf("No such background process exists\n");
}
else{
pid_t p1 = getpid();
pid = job[no - 1].id;
signal(SIGTTOU, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
tcsetpgrp(0, getpgid(pid));
kill(pid, SIGCONT);
waitpid(pid, NULL, WUNTRACED);
tcsetpgrp(0, p1);
signal(SIGTTOU, SIG_DFL);
signal(SIGTTIN, SIG_DFL);
delete_job(pid);
}
}