相关文章推荐
考研的猕猴桃  ·  Enable content on a ...·  1 年前    · 
小眼睛的帽子  ·  VS2019 Razor 语法 ...·  2 年前    · 
卖萌的登山鞋  ·  Mathematica ...·  2 年前    · 
苦恼的雪糕  ·  maven - ...·  2 年前    · 

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am used to using this command line to kill any process match said COMMAND

for i in $(ps -ef | grep COMMAND | awk '{ print $2 }'); do kill -9 "$i" &>/dev/null;done

shellcheck does not like it much and suggests

root@singa /home # shellcheck run
In run line 4:
for i in $(ps -ef | grep COMMAND | awk '{ print $2 }'); do kill -9 "$i" &>/dev/null;done
           ^-- SC2009: Consider using pgrep instead of grepping ps output.

what are the flags needed to complete this here replacing the XXX

for i in $(pgrep XXX | grep COMMAND | awk '{ print $2 }'); do kill -9 "$i" &>/dev/null;done

I have already checked the man page for pgrep.

Did you even try just running pgrep COMMAND before trying to drop it in the place of ps in your script? That should make it clear what has hone wrong with what you did. – DopeGhoti Jun 14, 2018 at 21:51

i have done below method

for i in pickup hald-runner; do pgrep $i | awk '{print "kill" " "  $1}'| sh;done

Here pickup,hald-runner is the process names