sed是否阻止? [英] Is sed blocking?
问题描述
我对sed的印象没有任何阻挠,因为当我说时:
I had the impression sed wasn't blocking, because when I do say:
iostat | sed
sed
在数据到达时对其进行处理,但是当我这样做时
sed
processes the data as it arrives, but when I do
iostat | sed | netcat
然后sed
阻止netcat
.
我说得对吗?
推荐答案
sed
当不打印到终端时将以缓冲模式工作.这意味着默认情况下它将尝试填充内部缓冲区,然后再进行任何处理和输出.
sed
will work in buffered mode when it doesn't print to a terminal. This means that it will try to fill its internal buffer before doing any processing and output by default.
这样做是为了增加吞吐量,因为通常在管道中,您无需关心时间,而是希望在给定时间内处理尽可能多的数据.
This is done to increase throughput, because normally in a pipe you don't care about the timing, but want as much data processed in a given time as possible.
将-u
传递给sed将使其不带缓冲地工作,因此以与输出到终端时相同的方式工作.
Passing -u
to sed will tell it to work unbuffered, therefore working the same way it works when output goes to a terminal.
这篇关于sed是否阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!