简体   繁体   中英

(Linux, C) Two threads, two separate text windows in the screen, how to do it?

I have two threads. The main thread and two others created with *pthread_create*, for instance thread_1 and thread_2.

The main thread writes the output in the terminal that i used to run the program. Then, i want to create two new windows, in which thread_1 and thread_2 will write some text.

i tried to use the system call "system()" and run "/bin/bash" but there is no new terminal appearing after that.

now, i am thinking to use some graphic library (g2, SDL...).

i searched the web for some hours and cant find a good solution. All i just need is to output text in independent windows, i don't want any kind of drawings, only text lines.

i am using Linux mint and C language.

Do you need the program to open the other two windows? If not:

Have each thread write to a separate file. Manually open two more windows. Use the bash command 'tail -f' in each of the new windows to display the output of each file.

想到的最接近的非GUI解决方案是ncurses

Thanks for the advices.

I achieved a solution for my problem with the Jay's hint.

It's very simple. i put the program writing the data to a file. (closest to the fifo idea)

then, inside the program i run this:

system("mate-terminal -e --command='tail -f filename.txt'");

and voilá! It creates a new terminal window and runs the command tail -f.

Thanks for your answers, they helped me thinking in that solution. I tried the ncurses but had problems in installing the package and then compiling with the -lncurses flag. I will try ncurses someday, but now the problem is solved.

bye

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM