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

  • SEARCH
  • Home
  • 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 798595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:59:49+00:00 2026-05-14T22:59:49+00:00

Is there any possibility to achieve different redirections for standard output like printf(3) for

  • 0

Is there any possibility to achieve different redirections for standard output like printf(3) for different POSIX thread? What about standard input?

I have lot of code based on standard input/output and I only can separate this code into different POSIX thread, not process. Linux operation system, C standard library.
I know I can refactor code to replace printf() to fprintf() and further in this style.
But in this case I need to provide some kind of context which old code doesn’t have.

So doesn’t anybody have better idea (look into code below)?

#include <pthread.h>
#include <stdio.h>

void* different_thread(void*)
{
    // Something to redirect standard output which doesn't affect main thread.
    // ...

    // printf() shall go to different stream.
    printf("subthread test\n");

    return NULL;
}

int main()
{
    pthread_t id;
    pthread_create(&id, NULL, different_thread, NULL);

    // In main thread things should be printed normally...
    printf("main thread test\n");

    pthread_join(id, NULL);
    return 0;
}
  • 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-14T22:59:50+00:00Added an answer on May 14, 2026 at 10:59 pm

    You can do what you want if you create threads using clone, but POSIX.1 says that the threads must share open file discriptors.

    There are several tricks you could try, but you really should just convert the calls to the FILE * argument accepting functions.

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

Sidebar

Related Questions

Is there any possibility in the prefix-function of a given pattern to have something
Is there any possibility of creating a view like the following image? I do
I would like to know if there is any possibility that I can use
Is there any possibility to return multiple values from method? Something like this: def
Is there any possibility to see doc variables? It's Microsoft Word 2003, I have
Is there any possibility to select a option field by default in a g:select
Is there any possibility to extract globalize2 translation for specified locale without setting I18n.locale
Is there any possibility of changing the MySQL DB table's field name or adding
Is there any possibility to make a link or a button to close the
Is there any possibility using the drag&drop technology for dragging desktop images onto a

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.