-
Notifications
You must be signed in to change notification settings - Fork 0
/
fg.c
62 lines (44 loc) · 1.23 KB
/
fg.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "fg.h"
#include "list.h"
#include "main.h"
#include "headers.h"
void fg(char ** parsed, int args)
{
if(args != 2)
{
printf("Usage: fg <job number>");
}
else
{
pid_t fgPid;
char * procName;
fgPid = get_Pid(procList, atoi(parsed[1]) - 1);
procName = get_procname(procList, atoi(parsed[1]) - 1);
if(fgPid == -1)
{
printf("Error: No job with the given job number found\n");
}
else
{
setpgid(fgPid, getpgid(0));
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
tcsetpgrp(0, fgPid);
if(kill(fgPid, SIGCONT))
perror("fg");
int status;
waitpid(fgPid, &status, WUNTRACED);
tcsetpgrp(0, getpgid(0));
signal(SIGTTIN, SIG_DFL);
signal(SIGTTOU, SIG_DFL);
if(WIFSTOPPED(status))
{
printf("\nSuspended\t%s [%d]\n", procName, fgPid);
procList = insert(procList, fgPid, procName);
fgPid = -1;
}
fgPid = -1;
procList = delete(procList, fgPid, procName);
}
}
}