How to kill all processes with a given partial nam

2019-01-05 06:34发布

I want to kill all processes that I get by:

ps aux | grep my_pattern

How to do it?

This does not work:

pkill my_pattern

标签: linux bash posix
10条回答
Deceive 欺骗
2楼-- · 2019-01-05 07:04

If you need more flexibility in selecting the processes use

for KILLPID in `ps ax | grep 'my_pattern' | awk ' { print $1;}'`; do 
  kill -9 $KILLPID;
done

You can use grep -e etc.

查看更多
forever°为你锁心
3楼-- · 2019-01-05 07:07

Also you can use killall -r my_pattern. -r Interpret process name pattern as an extended regular expression.

killall -r my_pattern
查看更多
Explosion°爆炸
4楼-- · 2019-01-05 07:11

Kill all processes matching the string "myProcessName":

One liner:

ps -ef | grep 'myProcessName' | grep -v grep | awk '{print $2}' | xargs -r kill -9

Source: http://www.commandlinefu.com/commands/view/1138/ps-ef-grep-process-grep-v-grep-awk-print-2-xargs-kill-9

查看更多
Bombasti
5楼-- · 2019-01-05 07:11

you can use the following command to list the process

ps aux | grep -c myProcessName 

if you need to check the count of that process then run

ps aux | grep -c myProcessName |grep -v grep 

after which you can kill the process using

kill -9 $(ps aux | grep -e myProcessName | awk '{ print $2 }') 
查看更多
太酷不给撩
6楼-- · 2019-01-05 07:15

You can use the following command to

kill -9 $(ps aux | grep 'process' | grep -v 'grep' | awk '{print $2}')
查看更多
萌系小妹纸
7楼-- · 2019-01-05 07:17

You can use the following command to:

ps -ef | grep -i myprocess | awk {'print $2'} | xargs kill -9

or

ps -aux | grep -i myprocess | awk {'print $2'} | xargs kill -9

It works for me.

查看更多
登录 后发表回答