Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想每秒将 Mac OS X 中的当前网络流量 [b/s] 存储到一个文件中。
netstat -b -n 1 |awk '{print $3}' |tail -n +3 >traffic.txt
我应该想要 - 但第二个管道似乎被缓冲了,我需要尽快得到结果。
如果我只使用一个管道,一切都很好,但我最多需要这三个。
ulimit -p 0不起作用(未实施?)。有没有其他方法可以避免缓冲?
ulimit -p 0
awk默认情况下将缓冲其输出。打电话fflush()冲洗它。
awk
fflush()
netstat -b -n 1 |awk '{print $3;fflush()}' |tail -n +3 >traffic.txt
管道是缓冲区,当它们到达时它们会发送数据。我不知道有什么方法可以加快他们的速度。
还有,你是说>> traffic.txt最后吗?您的解决方案会截断,附加两个尖括号。
>> traffic.txt