title: Terminating Main on Secondary Process Completion
body: <p>I have a Main C program that creates two threads and each of those threads starts a process using a system() call. Is it possible to terminate the main program as soon as either of those processes created by the threads finish operating?</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;sys/shm.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  
  extern errno;
  key_t key = 1;
  int *shm;
  
  void* Start_Ether(){
      printf("Creating Ethernet Process\n");
      int ret = system("sudo ./Ether");
      if (ret &lt; 0){
          printf("Error Starting Ethernet Process\n");
      }
  }
  
  void* Start_Display(){
      printf("Creating Display Process\n");
      int ret = system("./Display");
      if (ret &lt; 0){
          printf("Error Starting Display Process\n");
      }
  }
  
  int main (int argc, char **argv)
  {                       
      pthread_t Ether, opengl;
      int ret1, ret2;
      printf("**********************************************\nMain Started\n**********************************************\n");   
      ret2 = pthread_create(&amp;opengl, NULL, &amp;Start_Display, NULL);
      if (ret2 != 0){
         printf("Error in Creating Display Thread\n");
      }
      ret1 = pthread_create(&amp;Ether, NULL, &amp;Start_Ether, NULL);
      if (ret1 != 0){
          printf("Error in Creating Ether Thread\n");
      }
      while(1){
          continue;   
      }
      return 1;
  }
  </code></pre>