title: C exiting a program correctly
body: <p>Hello I am writing a c program which runs then waits for it to complete then executes an if condition. However after the child process completes it does not execute the rest of code in parent. Any advice would be great. Thanks</p>
  
  <p>AA</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;string.h&gt;    
  int main() {
  
      int D, waitVal3, waitVal4;
              D = fork();
          if(D == 0)
          {
              execv("DD", 0);
          }
              if(D != 0)
          {
              printf("\nPid = %d Code AA: created proccess Pid = %d (code DD)\n", getpid(), D);
          }
  
  
              waitVal3 = (waitVal4);
             //NEVER ENTERS THIS CONDITION
          printf("WAIT VAL: %d", waitVal3);
              if(waitVal3 == D)
              {
                  printf("\nPid = %d Code AA: process Pid = %d terminated\n", getpid(), D);
  
              }
          return 0;
  
  }
  </code></pre>
  
  <p>DD</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;signal.h&gt;
  
  int main (int argc, char *argBB[]) {
  
      int C3, waitVal, waitVal2, ps;
      C3 = fork(); 
  
      if(C3 != 0)
      {
          printf("\nPid = %d Code DD: created proccess Pid = %d (code CC)\n", getpid(), C3);
      }
      if( C3 == 0 )
      {
          execv("CC", 0);
          printf("\nexecv failed\n");
          exit(0);
      }
  
      if(C3 &lt; 0)
      {
          printf("Fork failed");
          exit(1);
      }
  
      ps = fork();
      if(ps != 0)
      {
          printf("\nPid = %d Code DD: created proccess Pid = %d (code ps)\n", getpid(), ps);
      }
  
      if( ps == 0 )
      {
          char command[50];
          strcpy(command, "ps -u username");
          system(command);    
          exit(11);
          kill(ps, SIGKILL);//KILL PROCCESS PS HERE
      }
  
      waitVal = wait(waitVal2);
  
      if(waitVal == ps)
          {
          printf("\nPid= %d Code DD: process Pid = %d terminated\n", getpid(), ps);
              printf("\nPid = %d Code DD: killing process Pid = %d\n", getpid(), C3);
              kill(C3, SIGKILL);
              printf("\nPid= %d Code DD: process Pid = %d terminated\n", getpid(), C3);
          printf("\nPid = %d Code DD: terminating\n", getpid());
  
          exit(7);
          }
  
      return 0;
  
  
  
  }
  </code></pre>