2016-01-31 32 views
1

Hellow。 我有非常简单的C程序。我在程序中创建管道(标准,非命名)。我可以在终端读取现有进程的管道吗(使用>或猫的流?)。我尝试了但我的命令什么也不做。我知道tkat我可以创建对外部I/O非常容易的命名管道。 我的管道数为/ proc/number/fd 为什么我需要它?只是从调试(但不只是,我知道gdb可以看管道)。当我fork过程中,孩子继承pts(终端)和std io/out。改变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 
} 

 
>rnpit& 
[1] 1077 
>ll /proc/${!}/fd 
total 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 -> pipe:[399466140] 
l-wx------ 1 armali ARNGO_res4 64 Apr 4 09:22 4 -> pipe:[399466140] 
>cat /proc/${!}/fd/3 
pipe