-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbgProcessEnd.c
More file actions
51 lines (46 loc) · 1.36 KB
/
bgProcessEnd.c
File metadata and controls
51 lines (46 loc) · 1.36 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
49
50
51
#include "header.h"
#include "JobStruct.h"
bool overkillflag = false;
void bgProcessEnd(job *jobArr, int *jobIter, char *home_dir, bool *kjobFlagPtr)
{
// printf("hello\n");
pid_t pid;
int stat;
while ((pid = waitpid(-1, &stat, WNOHANG)) > 0)
{
if (pid <= 0)
{
return;
}
for (int i = 0; i < *jobIter; i++)
{
// printf("%d ", jobArr[i].id);
if (((jobArr[i].id == pid && WIFEXITED(stat)) || (*kjobFlagPtr == 0 && jobArr[i].id == pid)) || overkillflag)
if (jobArr[i].running)
{
printf("\n");
//debugging
printf("%s with pid %d ", jobArr[i].name, jobArr[i].id);
//
int xStat = WEXITSTATUS(stat);
if (xStat == 0)
printf("exitted normally\n");
else
printf("exitted with some errors\n");
if (xStat == 0)xStat++;else xStat = -1;
print_PS1(home_dir, xStat);
fflush(NULL);
jobArr[i].running = false;
break;
}
}
}
if (overkillflag)
*jobIter = false;
overkillflag = false;
return;
}
void overKillFlagTrue()
{
overkillflag = true;
}