Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top