了解命名管道行为

时间:2018-09-25 19:15:51

标签: bash shell sh named-pipes

我有一些像这样的shell代码:

rm -f myfifo && mkfifo myfifo
(
    echo "data1" > myfifo
    echo "wrote first"
    echo "data2" > myfifo
    echo "wrote second"
) &

read -r ONE <myfifo
echo "$ONE" 
read -r TWO <myfifo
echo "$TWO"

我希望我会得到以下输出:

wrote first
data1
wrote second
data2

但是我得到以下输出:

wrote first
wrote second
data1

然后它永远挂起。 关于命名管道,我不了解什么原则?

谢谢。

0 个答案:

没有答案