-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.c
81 lines (69 loc) · 1.48 KB
/
start.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "stdio.h"
#include <unistd.h>
#include "string.h"
#include <stdlib.h>
#include <signal.h>
sigset_t signals;
struct Projects {
char name[20];
char path[128];
};
static char basePath[1024];
int pids [5];
int pid = -1;
static struct Projects projectsArray[] = {
{"auth", "/auth-service"},
{"file", "/file-service"},
{"stats", "/statistics-Service"},
{"notes", "/note-service"},
{"angular", "/frontend"}
};
void signal_handler(int signum) {
int i=0;
for(i;i<5;i++)
kill(pids[i],SIGKILL);
exit(0);
}
char* createWorkingPath(char* folderName) {
strcat(basePath, folderName);
return basePath;
}
void startDotnetProcess(char* folderName) {
chdir(createWorkingPath(folderName));
system("dotnet run");
}
void startAngularProcess(int last) {
chdir(createWorkingPath(projectsArray[last].path));
system("ng serve");
}
int main(void) {
signal(SIGTERM,signal_handler);
getcwd(basePath, sizeof(basePath));
int mainPID = getpid();
int numOfProjects = sizeof(projectsArray) / sizeof(projectsArray[0]);
for (int i = 0; i < numOfProjects - 1; i++) {
if (getpid() == mainPID) {
if (pid != 0) {
pid = fork();
pids[i] = pid;
}
if (pid == 0) {
sleep((rand()%100)/100*0.01);
startDotnetProcess(projectsArray[i].path);
break;
}
}
if (getpid() == mainPID)
sleep(0.2);
}
if (getpid() == mainPID) {
if (pid != 0) {
pid = fork();
pids[4] = pid;
}
if (pid == 0)
startAngularProcess(numOfProjects - 1);
}
sigsuspend(&signals);
return 0;
}