~ bash --version
GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2007 Free Software Foundation, Inc.
以下命令按预期工作:
~ ls hdfhdfhdhfd 2> >(wc -l)
1
...但是这不起作用,我想出了解决原因的想法:
~ truss -eaf bash -c 'true' 2> >( some command to process text)
>()
内的命令最终阻止等待输入。
如果我改为:
~ (true; truss -eaf bash -c 'true') 2> >( some command )
...它按预期工作,但这不起作用:
~ ( truss -eaf bash -c 'true') 2> >( some command )
# ^^^^^ ... note the 1st command is missing
如果我some command
= dd bs=1
,它会消耗并打印所有文本桁架将在stderr
上吐出,然后阻止。
只有在solaris中使用truss
时,才能在Linux中重现类似的行为。
答案 0 :(得分:1)
基于@ ccarton的回应,我想出了一个关于正在发生的事情的粗略想法。举例说明:
~ truss -eaf /usr/bin/perl -e 'print "Test\n"; sleep 5' 2> >(dd bs=1 | wc -l)
在另一个终端,我可以看到这个父/子层次结构:
bash
truss -eaf /usr/bin/perl -e printf "Test\n"; sleep 5
/usr/bin/perl -e printf "Test\n"; sleep 5
bash
dd bs=1
wc -l
truss
正在等待shell,但是dd
在stdin关闭之前不会退出...所以它们会死锁。
~ truss -eaf -o >(some command) another command
...导致some command
在当前shell下执行,因此truss
永远不会是它的祖先。
我在Linux中看到了相同的层次结构,但它没有死锁。