【问题标题】:How i can open separate terminal for each thread created in my application?如何为我的应用程序中创建的每个线程打开单独的终端?
【发布时间】:2011-09-02 09:31:50
【问题描述】:

基本上我有一个多线程应用程序,我想在其中查看结果和 printf 以及每个线程在不同终端上的所有输出,那么我该怎么做呢?

示例

如果在 ma 应用程序中创建了两个线程,那么我想为每个线程的输出打开两个单独的终端。

note: all i want to do in c language with my linux machine

【问题讨论】:

    标签: c linux multithreading terminal


    【解决方案1】:

    这是一个在不同 tty 上打印一行的示例:

    #include #include 整数 主要(int argc,char ** argv) { 字符 *path = argc > 1 ? argv[1]:“/dev/ttys017”; 文件 *tty = fopen( 路径, "a" ); 如果(tty == NULL){ 错误(路径); 退出(EXIT_FAILURE); } fputs("一个字符串\n", tty); }

    每个线程都可以在指定的终端上打开一个 FILE * 命令行。如果你想创建终端,你 可以查看 openpty 等的文档。要获取 特定终端的名称,只需在 shell 中运行“tty” 那个终端。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-03
      • 2011-07-05
      • 2012-02-25
      相关资源
      最近更新 更多