管道系统调用

时间:2015-03-10 20:22:46

标签: c linux pipe fork strace

如何从strace输出中看到已经建立了将流程链接在一起的命令管道? 此外,所有流程都可以互相交流

execve("./mypipes", ["./mypipes"], [/* 57 vars */]) = 0
arch_prctl(ARCH_SET_FS, 0x7ff0f5cbd700) = 0
pipe([3, 4])                            = 0
pipe([5, 6])                            = 0
clone(Process 32313 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ff0f5cbd9d0) = 32313
[pid 32312] clone(Process 32314 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ff0f5cbd9d0) = 32314
[pid 32312] clone(Process 32315 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ff0f5cbd9d0) = 32315
[pid 32313] execve("/bin/cat", ["cat", "/etc/passwd"], [/* 57 vars */] <unfinished ...>
[pid 32312] exit_group(32315)           = ?
[pid 32314] execve("/usr/bin/cut", ["cut", "-f1", "-d:"], [/* 57 vars */] <unfinished ...>
[pid 32313] <... execve resumed> )      = 0
[pid 32314] <... execve resumed> )      = 0
[pid 32315] execve("/usr/bin/sort", ["sort"], [/* 57 vars */]) = 0
[pid 32313] arch_prctl(ARCH_SET_FS, 0x7f4392d83700) = 0
[pid 32314] arch_prctl(ARCH_SET_FS, 0x7fb7fd75e700) = 0 
[pid 32315] arch_prctl(ARCH_SET_FS, 0x7fbda4e43700) = 0
[pid 32313] exit_group(0)               = ?
Process 32313 detached

1 个答案:

答案 0 :(得分:0)

是管道系统调用创建2个管道,让我们称之为父对话和父听。 fd [0]是父对话,fd [1]是父听。孩子从fd [0]读取并写入fd [1]