So I'm trying to write this program that requires only the parent to fork multiple process that will all do the same time.
I am able to generate 3 processes, but only two are from the parent and other one is a result of one of the children's.
Code:
printf("Parent = %d\n", getpid());
for(i=0;i<2;i++) {
if((pid[i] = fork()) == 0 ) {
pid = getpid();
printf("\tChild = %d\n", pid);
printf("I JUST GOT FORKED %d\n", getpid());
}
else
printf("I AM PARENT %d\n", getpid());
}
Output:
Code:
Parent = 9727
I AM PARENT 9727
Child = 9728
I JUST GOT FORKED 9728
I AM PARENT 9727
I AM PARENT 9728
Child = 9730
I JUST GOT FORKED 9730
Child = 9729
I JUST GOT FORKED 9729