-
Process/childrens
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;
}
-
Each child needs to stop when it reaches the end of it's if ( pid == 0 ) block.
-
How i can do a process that execute the shell command "ps u" every 2secs ? Its with "exec" functions? Anyone can show me how to do that?
-
if ( fork() == 0 ) execl()
Plus some manual reading, and maybe a board search, since this has been done before.
-
Perhaps even post on the linux board next time. fork() isn't supported on windows.