Hi, i want to create 3children processes from one "Father process" but when i test my code i see on the Shell that the "Father" create children1, children1 create children2 and children2 create children3, and i want is to create all the 3children from "Father" process, anyone can help?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
int main(){
int filho1,filho2,filho3;
filho1 = fork();
if (filho1 == 0){
printf("[%d] Sou o filho1!\n", getpid());
printf("[%d] O meu pai é: %d\n", getpid(), getppid());
}
filho2 = fork();
if (filho2 == 0){
printf("[%d] Sou o filho2!\n", getpid());
printf("[%d] O meu pai é: %d\n", getpid(), getppid());
}
filho3 = fork();
if (filho3 == 0){
printf("[%d] Sou o filho3!\n", getpid());
printf("[%d] O meu pai é: %d\n", getpid(), getppid());
}
return 0;
}