bash - 将 stderr 重定向到使用进程替换创建的子 shell 时出现问题

标签 bash solaris-10 truss

~ 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

如果我制作一些命令 = dd bs=1,它会消耗并打印所有文本 truss 会在 stderr 上吐出,然后阻塞。

只有在 solaris 中使用 truss 时,我才能在 Linux 中重现类似的行为。

最佳答案

根据@ccarton 的回复,我对正在发生的事情有了一个大概的了解。举例说明:

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

在另一个终端我可以看到这个父/子层次结构:

  1. 庆典
    1. truss -eaf/usr/bin/perl -e printf "Test\n";睡 5
      1. /usr/bin/perl -e printf "测试\n";睡 5
      2. 庆典
        1. dd bs=1
          1. wc -l

truss 正在等待 shell,但是 dd 不会退出,直到它的标准输入被关闭...所以他们死锁了。

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

... 导致某些命令 在当前 shell 下执行,因此 truss 永远不是它的祖先。

我在 Linux 中看到了相同的层次结构,但它并没有死锁。

关于bash - 将 stderr 重定向到使用进程替换创建的子 shell 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16368118/

相关文章:

bash - 是否可以在使用原始脚本的同时运行重复的 bash 脚本?

java - Glassfish v3 "unable to find valid certification path to requested target"

c - 使用 truss 调试 open() 命令调用

windows - 在打开 Emacs 时自定义窗口

bash - 我可以在不使用 cat 的情况下有条件地将 shell 函数作为管道 "disappear"吗?

bash - UNIX 初学者 : grep save to a file doesn't work

使用 MySQL 5.6 的 Solaris 10 中的 MySQL 性能问题

perl - 无法使用 perl5.8.4 在 @INC 中运行 perl 程序 : Can't locate Time/Piece. pm 并且无法使用 perl 5.12.3 在 @INC 中找到 DBI.pm

macos - 如何在 Mac OS X 中跟踪程序的系统调用?