有没有办法清除正在运行的进程的标准输出 [英] Is there a way to flush stdout of a running process
本文介绍了有没有办法清除正在运行的进程的标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个长时间运行的过程,其中stdout重定向到文件.例如:
I have a long-running process with stdout redirected to a file. E.g.:
./my-script.sh > file.txt &
部分stdout仍被缓存,但是我想将其刷新到文件中,以便更早地看到结果.有办法吗?
Part of the stdout is still cached, but I would like to flush it to the file, to see the results earlier. Is there a way to do it?
推荐答案
缓存由libc处理.您可以使用stdbuf
命令更改缓冲区大小:
The caching is handled by the libc. You can use the stdbuf
command to change the buffer size:
stdbuf -o0 ./my-script.sh > file.txt &
-o0
将stdout的缓冲区大小设置为0
.也许您还想要-e0
作为stderr.
-o0
sets the buffer size for stdout to 0
. Probably you also want -e0
for stderr.
这篇关于有没有办法清除正在运行的进程的标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文