2013-05-03 62 views
3
~ bash --version 
GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10) 
Copyright (C) 2007 Free Software Foundation, Inc. 

下面的命令按預期工作:有問題重定向標準錯誤創建W A子shell /進程替換

~ 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

也許某些shell和default Shell組合在Solaris和Linux之間的差異產生了這些不同的行爲。 – Efren 2013-06-20 07:51:43

+1

也許嘗試使用'-o'而不是重定向 – ccarton 2013-06-20 15:38:26

+0

ccarton,您應該將其作爲回答發佈。它確實解決了這個問題,但是我仍然很好奇爲什麼這首先發生。'truss'是我見過這種行爲的唯一終端應用程序。 – 2013-06-20 18:39:01

回答

1

基於@ccarton的迴應我已經對發生了什麼事情有了一個大概的想法。爲了說明:

~ truss -eaf /usr/bin/perl -e 'print "Test\n"; sleep 5' 2> >(dd bs=1 | wc -l) 

在另一端,我可以看到這個父/子層次:

  1. bash
    1. truss -eaf /usr/bin/perl -e printf "Test\n"; sleep 5
      1. /usr/bin/perl -e printf "Test\n"; sleep 5
      2. bash
        1. dd bs=1
          1. wc -l

truss正在等待的外殼,但dd不會退出,直到它的標準輸入被關閉......所以他們死鎖。

~ truss -eaf -o >(some command) another command 

...使some command當前shell下執行這樣truss是從來沒有它的祖先。

我在Linux中看到了相同的層次結構,但它沒有死鎖。