Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:55:30+00:00 2026-05-25T12:55:30+00:00

I have multi thread application in which I’m creating a thread like this: int

  • 0

I have multi thread application in which I’m creating a thread like this:

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<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<argc-1;i++)
    {
      pthread_create (&thread_id[i], NULL , &thread_function, &thread_data[i]);
    }      
}

Now in the thread function, I want to redirect stderr & stdout in one separate file as per thread. Something like a thread log file.

How can I do so?

Edit:

If thread specific prints can be displayed on different terminal..? I mean if there are 2 threads then it opens 2 terminals & prints each threads data on different terminals.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:55:30+00:00Added an answer on May 25, 2026 at 12:55 pm

    If you really must do this…

    First you need to create 2 pthread_key_ts, one for stdout and one for stderr. These can be created using pthread_key_create, and they must be accessable from all threads. Let’s call them stdout_key and stderr_key.

    When a thread is being created:

    FILE *err = ..., *out = ...;
    pthread_setspecific(stdout_key, out);
    pthread_setspecific(stderr_key, err);
    

    and then in your header file:

    #define stdout (FILE*)pthread_getspecific(stdout_key)
    #define stderr (FILE*)pthread_getspecific(stderr_key)
    #define printf(...) fprintf(stdout, ##__VA_ARGS__)
    

    then just use:

    fprintf(stderr, "hello\n");
    fprintf(stdout, "hello\n");
    printf("hello\n");
    

    I don’t recommend this approach though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a layered application in Java which has a multi thread data access
see basically i have one multi-thread application in which i want to see the
I have a multi-threaded application written in Python in which one thread takes care
I have created an multi thread application on IIS (ASP.NET MVC), When the threading
I have a multi-threaded application which parses some text and it needs to use
I'm trying to solve a classic problem - I have a multi-threaded application which
I have a multi-threaded application which needs to display certain dates to the user.
I am creating a multi-threaded application. However, I have experienced lots of unexpected behavior
Hi: I have a multi thread Java application. There are many temporary objects. -XX:MaxTenuringThreshold=1
We have created a multi-threaded application which process/parse big files (few hundred MB's) simultaneously.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.