简体   繁体   English

(Linux,C)两个线程,屏幕中两个独立的文本窗口,该怎么办?

[英](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. 主线程和其他两个用* pthread_create *创建的线程,例如thread_1和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. 然后,我想创建两个新窗口,其中thread_1和thread_2将写入一些文本。

i tried to use the system call "system()" and run "/bin/bash" but there is no new terminal appearing after that. 我试图使用系统调用“ system()”并运行“ / bin / bash”,但此后没有出现新的终端。

now, i am thinking to use some graphic library (g2, SDL...). 现在,我正在考虑使用一些图形库(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. 我正在使用Linux Mint和C语言。

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. 在每个新窗口中使用bash命令“ tail -f”显示每个文件的输出。

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

Thanks for the advices. 感谢您的建议。

I achieved a solution for my problem with the Jay's hint. 我用Jay的提示解决了我的问题。

It's very simple. 非常简单 i put the program writing the data to a file. 我把程序写入数据到文件。 (closest to the fifo idea) (最接近fifo的想法)

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. 它创建一个新的终端窗口并运行命令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. 我尝试了ncurses,但是在安装软件包然后使用-lncurses标志进行编译时遇到了问题。 I will try ncurses someday, but now the problem is solved. 我有一天会尝试ncurses,但现在问题已解决。

bye 再见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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