0

Extened question from In multi thread application how can i redirect stderr & stdout in separate file as per thread?

see some how i want to keep all printf and error/warning message produced in each thread in different log-file.

FILE * freopen ( const char * filename, const char * mode, FILE * stream ); 

freopen function redirects 3rd argument stream into 1st argument file name. So now i want to ask you in multi-theread application can i do that with help of freopen()... how?

Community
  • 1
  • 1
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222

1 Answers1

1

Since all resources are shared in a threaded application, including files, changing stdin or stdout in one thread changes them for all threads. If you want to change it in just a single thread then use fork to create a new process instead.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621