bash:静默杀死后台函数进程 [英] bash: silently kill background function process
本文介绍了bash:静默杀死后台函数进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
贝壳大师,
我有一个 bash shell 脚本,我在其中启动了一个后台函数,比如 foo()
,以显示一个无聊而冗长的命令的进度条:
I have a bash shell script, in which I launch a background function, say foo()
, to display a progress bar for a boring and long command:
foo()
{
while [ 1 ]
do
#massively cool progress bar display code
sleep 1
done
}
foo &
foo_pid=$!
boring_and_long_command
kill $foo_pid >/dev/null 2>&1
sleep 10
现在,当 foo
死亡时,我看到以下文本:
now, when foo
dies, I see the following text:
/home/user/script: line XXX: 30290 Killed foo
这完全破坏了我的非常酷的进度条显示.
This totally destroys the awesomeness of my, otherwise massively cool, progress bar display.
我如何摆脱这条消息?
推荐答案
kill $foo_pid
wait $foo_pid 2>/dev/null
顺便说一句,我不知道你的非常酷的进度条,但是你见过 Pipe Viewer (pv) 吗?http://www.ivarch.com/programs/pv.shtml
BTW, I don't know about your massively cool progress bar, but have you seen Pipe Viewer (pv)? http://www.ivarch.com/programs/pv.shtml
这篇关于bash:静默杀死后台函数进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文