-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfg_bg.c
45 lines (42 loc) · 891 Bytes
/
fg_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
42
43
44
45
#include "prototype.h"
extern struct utsname UNAME;
extern char* SYSTEM_NAME;
extern char HOME[500005];
extern char* USER;
extern char PWD_ABS_NAME[500005];
extern char PWD_NAME[500005];
extern DIR* PWD;
extern char* cmd;
extern int num_built_in;
extern char children_name[100000][51];
extern pid_t bg_children_PIDs[1000];
extern int bg_num_children;
extern pid_t currentChildPID;
extern pid_t startShellPID;
extern volatile sig_atomic_t run_clock;
void fg(int jobN)
{
int* status;
if(jobN > bg_num_children)
{
fprintf(stderr, "Specified job does not exist\n");
return;
}
else
{
currentChildPID = bg_children_PIDs[jobN-1];
waitpid(currentChildPID, status, WUNTRACED);
}
}
void bg(int jobN)
{
if(jobN > bg_num_children)
{
fprintf(stderr, "Specified job does not exist\n");
return;
}
else
{
kill(bg_children_PIDs[jobN-1], SIGCONT);
}
}