hi everyone;
i want to make scheduling in my program. For example

Code:
pid2 = fork;
switch(pid){
   case -1:
      error
   case 0:
      child1
      loop;
   default:
      pid2 = fork();
      switch(pid2){
         case -1:
            error
         case 0:
            child2;
            loop
          default:
             mainProcess;
             loop;
        }
   }
All processes do something and in communication with each other by pipes. they send and receive data in loops. The problem is, i want to run firstly child1 and then child2 and finally parent in each loop iteration until some condition is satisfied.
how can i do that?