X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;ds=inline;f=src%2Fbootstrap.c;fp=src%2Fbootstrap.c;h=1df77c16c8852aef5f11adee20876e234725a52a;hb=8c1fe1f8edbdb17e876546e623bc65e7205c7335;hp=0000000000000000000000000000000000000000;hpb=a997ce1184d3fee6c85d03afd0f5828a1bb5f8de;p=wsti_so.git diff --git a/src/bootstrap.c b/src/bootstrap.c new file mode 100644 index 0000000..1df77c1 --- /dev/null +++ b/src/bootstrap.c @@ -0,0 +1,50 @@ +#include +#include + +/* strerror, and errno family.. */ +#include + +/* exec family.. */ +#include + +/** 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