title: How to pause a process and continue the program?
body: <p>I'd like to know if there is a way to pause a process but continue the program.  </p>
  
  <p>I need to create processes like this:<br>
  <a href="https://i.stack.imgur.com/aZ5Wi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aZ5Wi.png" alt="enter image description here"></a></p>
  
  <p>But when I hit <code>P4</code> it ends, dies and then P2 creates P5. Then P2 Dies and P1 creates P3 and the same thing happens there.  </p>
  
  <p>I need to create the whole 'tree' before the processes start to die.<br>
  Can't use <code>wait</code> nor <code>waitpid()</code> because it only targets it's son.  </p>
  
  <p>Is there a way to Pause P4 and continue from it's father ?<br>
  If I can't how could I achieve my goal ?  </p>
  
  <p>My currently code:  It's creating in this order:  </p>
  
  <blockquote>
    <p>P1 -> P2 -> P4 -> P4 DIES -> P5 -> P5 DIES -> P2 DIES -> 
    P3 -> P6 -> P6 DIES -> P7 -> P7 DIES -> P3 DIES -> P1 DIES</p>
  </blockquote>
  
  <pre><code>    #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/wait.h&gt; 
  #include &lt;time.h&gt;
  
  
  int main(){
      clock_t t;
      double time_taken;
      t = clock();
      int status;
      pid_t idProcesso, pai;
      printf("P1 created: %d\n", getpid());
  
      idProcesso = fork();
      switch(idProcesso)
      {
          case -1: exit(1);
  
          case 0: //P2
              printf("P2 created: %d  -  son of P1: %d\n", getpid(), getppid());
              idProcesso = fork();
              switch(idProcesso)
              {
                  case -1: exit(1);
  
                  case 0: //P4
                      printf("P4 created: %d  -  son of P2: %d\n", getpid(), getppid());
                      sleep(1);
                      break;
                  default://P2
                      idProcesso = fork();
                      switch(idProcesso)
                      {
                          case -1: exit(1);
  
                          case 0://P5
                              printf("P5 created: %d  -  son of P2: %d\n", getpid(), getppid());
  
                              break;
                          default://P2
                              sleep(1);
                              break;
                      }
  
                      break;
              }
              break;
          default:
  
              idProcesso = fork();
              switch(idProcesso)
              {
                  case -1: exit(1);
  
                  case 0://P3
                      printf("P3 created: %d  -  son of P1: %d\n", getpid(), getppid());
                      idProcesso = fork();
                      switch(idProcesso)
                      {
                          case -1: exit(1);
  
                          case 0://P6
                              printf("P6 created: %d  -  son of P3: %d\n", getpid(), getppid());
                              sleep(1);
                              break;  
                          default://P3
                              idProcesso = fork();
                              switch(idProcesso)
                              {
                                  case -1: exit(1);
  
                                  case 0://P7
                                      printf("P7 created: %d  -  son of P3: %d\n", getpid(), getppid());
                                      break;
                                  default://P3
  
                                      break;
                              }
                              sleep(1);
                          break;
                      }
                      break;
  
                  default:
                      sleep(4);
                      break;
              }
              break;
      }
  
  
  
      printf("Process id: %d terminated\n", getpid());
      exit(0);
  }
  </code></pre>