【问题标题】:Read noonnamed pipe in terminal在终端中读取 noonnamed 管道
【发布时间】:2016-01-31 13:50:24
【问题描述】:

你好。 我有非常简单的 C 程序。我在程序中创建管道(标准,未命名)。我可以在终端中读取现有进程的管道(使用 > 或 cat 进行流式传输吗?)。我尝试了一下,但我的命令什么也没做。我知道 tkat 我可以创建对外部 I/O 非常容易的命名管道。 我有 /proc/number/fd 的管道数 为什么我需要它?仅来自调试(但不仅如此,我知道 gdb 可以看起来像管道)。当我 fork 进程时,子进程继承 pts(终端)和 std io/out。更改 pts 是可能的,但这是不好的方法。所以我将打开下一个终端并在其中流式传输现有的进程pipie。 有可能(体面的、令人头晕的方式让我不感兴趣)还是我必须使用命名管道?

【问题讨论】:

    标签: c linux process pipe pts


    【解决方案1】:

    我可以在终端中读取现有进程的管道吗(使用 > 或 猫?)

    是的,你可以。示例rnpit.c

    #include <string.h>
    main()
    {
        int pipefd[2];
        pipe(pipefd);
        write(pipefd[1], "pipe", strlen("pipe"));
        sleep(99);  // give us time to read the pipe
    }
    

    >坑坑& [1] 1077 >ll /proc/${!}/fd 共 0 lrwx------ 1 armali ARNGO_res4 64 Apr 4 09:22 0 -> /dev/pts/5 lrwx------ 1 armali ARNGO_res4 64 Apr 4 09:22 1 -> /dev/pts/5 lrwx------ 1 armali ARNGO_res4 64 Apr 4 09:22 2 -> /dev/pts/5 lr-x------ 1 armali ARNGO_res4 64 Apr 4 09:22 3 -> 管道:[399466140] l-wx------ 1 armali ARNGO_res4 64 Apr 4 09:22 4 -> 管道:[399466140] >cat /proc/${!}/fd/3 管道

    【讨论】:

      猜你喜欢
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 1970-01-01
      • 1970-01-01
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多