title: In multi thread application how can I redirect stderr & stdout in separate file as per thread?
body: <p>I have multi thread application in which I'm creating a thread like this:</p>
  
  <pre><code>int main(int argc,char *argv[])
  {
      pthread_t thread_id[argc-1];
      int i;
      struct parameter thread_data[argc-1];
      int status;
      for(i=0;i&lt;argc-1;i++)
      {
        thread_data[i].ip_filename = argv[i+1];
        strcpy (thread_data[i].op_filename,argv[i+1]);
        strcat (thread_data[i].op_filename,".h264");
      }
  
      for(i=0;i&lt;argc-1;i++)
      {
        pthread_create (&amp;thread_id[i], NULL , &amp;thread_function, &amp;thread_data[i]);
      }      
  }
  </code></pre>
  
  <p>Now in the thread function, <strong>I want to redirect <code>stderr</code> &amp; <code>stdout</code> in one separate file as per thread.</strong> Something like a thread log file.</p>
  
  <p>How can I do so?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>If thread specific prints can be displayed on different terminal..? I mean if there are 2 threads then it opens 2 terminals &amp; prints each threads data on different terminals.</p>