Reputation: 27210
see basically i have one multi-thread application in which i want to see the result & printf and all output of each thread on different terminal so how can i do that.?
Example :
if there are two thread created in ma application then i want to open two separate terminal for each thread's output.
note: all i want to do in c language with my linux machine
Upvotes: 1
Views: 1784
Reputation: 212228
Here's an example that prints a line on a different tty:
#include <stdio.h> #include <stdlib.h> int main( int argc, char ** argv ) { char *path = argc > 1 ? argv[ 1 ] : "/dev/ttys017"; FILE *tty = fopen( path, "a" ); if( tty == NULL ) { perror( path ); exit( EXIT_FAILURE ); } fputs( "a string\n", tty ); }
Each thread could open a FILE * on a terminal specified on the command line. If you want to create the terminals, you can check the documentation for openpty, etc. To get the name of a particular terminal, just run "tty" in a shell on that terminal.
Upvotes: 2