Initial bootstrap program.
[wsti_so.git] / src / bootstrap.c
diff --git a/src/bootstrap.c b/src/bootstrap.c
new file mode 100644 (file)
index 0000000..1df77c1
--- /dev/null
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+/* strerror, and errno family.. */
+#include <errno.h>
+
+/* exec family.. */
+#include <unistd.h>
+
+/** Number of processes to spawn */
+#define PROCESS_NUMBER 3
+
+char * processes[PROCESS_NUMBER] = {
+       "process1",
+       "process2",
+       "process3"
+};
+
+/**
+ * Bootstrap program used for starting all three main processes.
+ */
+int main(void) {
+
+       pid_t pid;
+       int i = 0;
+       int err = 0;
+
+       for (; i < PROCESS_NUMBER; i++) {
+               fprintf(stderr, "[%s] Forking process %d\n", "bootstrap", i);
+               pid = fork();
+
+               /* If it is child fork */
+               if (pid == 0) {
+                       err = execl(processes[i], processes[i], NULL);
+
+                       /*
+                        * According to manual, this will only occur
+                        * if there was an error in execl
+                        */
+                       if (err == -1) {
+                               fprintf(stderr, "[%s] Something went wrong when spawning %s. Error: %s\n",
+                                       "bootstrap", processes[i], strerror(errno));
+                       }
+               }
+       }
+
+       /* All processes should be now spawned. Close bootstrap program. */
+       
+       return 0;
+}
\ No newline at end of file