如果在标准错误中看到特定的字符串,我该如何杀死一个进程? [英] How can I kill a process when a specific string is seen on standard error?
本文介绍了如果在标准错误中看到特定的字符串,我该如何杀死一个进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要启动一个进程,可以说 foo
。我想正常看到stdout / stderr,但是 grep
字符串 bar
的stderr。在
stderr foo
中找到 bar
应该被杀死。
I need to start a process, lets say foo
. I would like to see the stdout/stderr as normal, but grep
the stderr for string bar
. Once bar
is found in the
stderr foo
should be killed.
这可能吗?
推荐答案
Tom Anderson的回答很好,但是 kill $(cat $ PIDFILE)
只会在我的系统上发生,如果 foo
自己终止,或通过Ctrl-C终止。以下解决方案适用于我
Tom Anderson’s answer is quite good, but the kill $(cat $PIDFILE)
will only happen on my system if foo
terminated on its own, or through Ctrl-C. The following solution works for me
while read g
do
if [[ $g =~ bar ]]
then
kill $!
fi
done < <(
exec foo 2> >(tee /dev/tty)
)
这篇关于如果在标准错误中看到特定的字符串,我该如何杀死一个进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文