-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbg.c
41 lines (39 loc) · 978 Bytes
/
bg.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
#include"headers.h"
void func_bg(char **a){
//pid_t is a data type to represent process id
pid_t pid;
pid = fork(); //creates a child process
//setpgid(0, 0);
strcpy(job[job_no].name, a[0]);
job[job_no].id = pid;
job_no++;
int status;
current_bg_pid = pid;
if(pid < 0){
perror("Error"); //no child process created
return;
}
else if(pid == 0){
if (signal(SIGINT, shandler) == SIG_ERR)
sleep(0);
signal(SIGTSTP, shandler);
if (signal(SIGTSTP, signal_handler));
while(sigsetjmp(cz_buf, 1) != 0);
//Returned to the newly created child process
if(execvp(a[0], a) == -1){
perror("Error");
}
exit(0);
}
else{
signal(SIGCHLD, handler);
return;
}
return;
}
void bg(int no){
if(no > job_no){
printf("Enter valid job number");
}
else kill(job[no - 1].id, SIGCONT);
}