title: How to wait for the child's termination and the signals at the same time?
body: <p>The application I am dealing with is multi-threaded. Each thread has a code segment which calls <code>fork()</code>, and in turn the child calls <code>execlp()</code>. But no two threads execute that code segment simultaneously (synchronized with mutex_locks). I need to wait for the child completion to proceed further. This is generally achieved by <code>wait*()</code> system calls. But in my case, I can't be blocked for whole 1 minute (expected child execution time) since I need to respond to the signals sent by main() thread. Below is a minimal thread function that helps in understanding the execution flow</p>
  
  <pre><code>void thread_func()
  {
      pthread_mutex_lock(&amp;fork_lock);
  
      pid_t fk_return = fork();
  
      if (fk_return &lt; 0) {
          goto thread_quit;
      }
      else if (fk_return == 0) {
          // Call execlp(). It will terminate after a minute or so.
      }
  
      /* Wait for child termination and signal */
  
      pthread_mutex_unlock(&amp;fork_lock);
  
      /* Non critical code segment */
  
      thread_quit:
      return NULL;
  }
  </code></pre>
  
  <p>So, how can I wait for both child termination and signals sent by main() at the same time ?</p>