Initial bootstrap program.
[wsti_so.git] / src / bootstrap.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 /* strerror, and errno family.. */
5 #include <errno.h>
6
7 /* exec family.. */
8 #include <unistd.h>
9
10 /** Number of processes to spawn */
11 #define PROCESS_NUMBER 3
12
13 char * processes[PROCESS_NUMBER] = {
14         "process1",
15         "process2",
16         "process3"
17 };
18
19 /**
20  * Bootstrap program used for starting all three main processes.
21  */
22 int main(void) {
23
24         pid_t pid;
25         int i = 0;
26         int err = 0;
27
28         for (; i < PROCESS_NUMBER; i++) {
29                 fprintf(stderr, "[%s] Forking process %d\n", "bootstrap", i);
30                 pid = fork();
31
32                 /* If it is child fork */
33                 if (pid == 0) {
34                         err = execl(processes[i], processes[i], NULL);
35
36                         /*
37                          * According to manual, this will only occur
38                          * if there was an error in execl
39                          */
40                         if (err == -1) {
41                                 fprintf(stderr, "[%s] Something went wrong when spawning %s. Error: %s\n",
42                                         "bootstrap", processes[i], strerror(errno));
43                         }
44                 }
45         }
46
47         /* All processes should be now spawned. Close bootstrap program. */
48         
49         return 0;
50 }