-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcom_fg.h
More file actions
48 lines (45 loc) · 1.03 KB
/
Copy pathcom_fg.h
File metadata and controls
48 lines (45 loc) · 1.03 KB
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
#ifndef COM_FG
#define COM_FG
#include "global.h"
int call_fg()
{
if (numargs != 2)
{
printf("%s: invalid number of arguments\n", commands[0]);
return 0;
}
if (str_is_num(commands[1]) == 0)
{
printf("%s: invalid argument\n", commands[0]);
return 0;
}
int arg1 = my_atoi(commands[1]);
if (arg1 > bgcommands_num || arg1 == 0)
{
printf("%s: no such job\n", commands[0]);
return 0;
}
__pid_t pid = getpgid(bgprocesses_ID[arg1 - 1]);
if (pid >= 0)
{
kill(bgprocesses_ID[arg1 - 1], SIGCONT);
tcsetpgrp(0, pid);
signal(22, (__sighandler_t)1);
signal(21, (__sighandler_t)1);
int x = waitpid(pid, NULL, WUNTRACED);
tcsetpgrp(0, getpgid(Shell_Id));
signal(22, ((__sighandler_t)0));
signal(21, ((__sighandler_t)0));
if (x == -1)
{
return 0;
}
}
else
{
printf("Process has been terminated.\n");
return 0;
}
return 1;
}
#endif