Sure. MK, I've tried your code but to me the structure of the classes is much easier.
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
void launch( void (*func)() );
void parent();
void child2();
void child3();
void child4();
void child5();
void child6();
void child7();
void child8();
pid_t pid;
int main(void)
{
fork();
launch(parent);
}
void launch( void (*func)() )
{
if( fork() == 0 )
{
printf("My PID is %d, my parent is %d\n ", getpid(), getppid());
func();
exit( 0 );
}
}
void parent()
{
launch( child2 );
launch( child3 );
wait(NULL);
wait(NULL);
}
void child2()
{
launch( child4 );
launch( child5 );
wait(NULL);
wait(NULL);
}
void child3()
{
launch( child6 );
wait(NULL);
}
void child4()
{
launch( child7 );
launch( child8 );
wait(NULL);
wait(NULL);
}
void child5()
{
}
void child6()
{
}
void child7()
{
}
void child8()
{
}