%20%E9%80%9A%E8%BF%87%20%60tail%20-f%60%20%E8%BF%9E%E6%8E%A5%E8%B5%B7%E6%9D%A5%20%7C%E5%8F%91%E9%80%81%E5%88%B0%20PIPE_in%20%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%9C%AA%E5%88%B0%E8%BE%BE%20PIPE_out.png)
1.创建命名 PIPE,pipe_in
并pipe_out
运行:
$ mkfifo pipe_in
$ mkfifo pipe_out
2.连接pipe_in
到pipe_out
:
TERM0: $ tail -f pipe_in > pipe_out
3.发送字符串hello world!
到pipe_in
并期望它到达pipe_out
:
TERM1: $ tail -f pipe_out
TERM2: $ echo "hello world!" > pipe_in
pipe_out
如果我在 中终止命令,我只能看到到达的字符串2.
。这似乎是一个缓冲问题,所以我决定运行上面的所有命令,stdbuf -i0 -e0 -o0 <command>
但它不起作用。
答案1
tail
只输出文件/流的最后 n 行。当您仍在生成行时,它无法知道哪一个是最后 n 个。
你尝试过类似的事情cat
吗?