-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinuxProject.c
More file actions
43 lines (36 loc) · 1.17 KB
/
linuxProject.c
File metadata and controls
43 lines (36 loc) · 1.17 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
#include "linuxProject.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
int main()
{
int status;
char exit_code[50];
swManager* mySwInfo = (swManager*)malloc(sizeof(swManager));
InitSwManager(mySwInfo);
readFileList(mySwInfo);
InitSWBlock(mySwInfo);
while(1)
{
mySwInfo->dpid = waitpid(-1, &status, 0);
if(mySwInfo->dpid != -1)
{
int idx = FindIndex(mySwInfo);
mySwInfo->sw_info[idx].int_restart++;
sprintf(mySwInfo->sw_info[idx].restart_count, "%d", mySwInfo->sw_info[idx].int_restart);
if(WIFEXITED(status)) {
sprintf(exit_code, "EXIT(%d)", WEXITSTATUS(status));
strcpy(mySwInfo->sw_info[idx].reason, exit_code);
}
else if(WIFSIGNALED(status)) {
sprintf(exit_code, "SIGNAL(%d).%s", WTERMSIG(status), strsignal(WTERMSIG(status)));
strcpy(mySwInfo->sw_info[idx].reason, exit_code);
}
restartProcess(mySwInfo, idx);
LogWrite(&(mySwInfo->sw_info[idx]));
LogInterface(mySwInfo);
}
}
}