-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_fg.c
More file actions
29 lines (28 loc) · 831 Bytes
/
execute_fg.c
File metadata and controls
29 lines (28 loc) · 831 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
#include"header.h"
#include"variables.h"
int execute_fg(char **args){
int status;
if(args[1] != NULL){
int idx = atoi(args[1]);
if(idx >= background_jobs || idx < 0)
printf("Specified job does not exist\nRun \"jobs\" for all background processes\n");
else{
if(kill(job[idx].pid, SIGCONT) < 0){
perror("kill(SIGCONT)"); // sending a signal to run in foreground
return 1;
}
int chd_pid = job[idx].pid;
pop_job(idx);
printf("Process in foreground\n");
//signal(SIGINT, proc_exit);
//wait(NULL);
waitpid(chd_pid, NULL, WCONTINUED & 0);
return 1;
}
}
else{
printf("Usage: fg [job number]\n");
return 1;
}
return 1;
}