Cómo eliminar todos los procesos con un nombre parcial dado?


Quiero eliminar todos los procesos que obtengo:

ps aux | grep my_pattern

¿Cómo hacerlo?

Esto no funciona:

pkill my_pattern
Author: John Kugelman, 2012-01-24

10 answers

Use pkill -f, que coincide con el patrón para cualquier parte de la línea de comandos

pkill -f my_pattern
 964
Author: Dor Shemer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-14 16:50:09

Matar todos los procesos que coincidan con la cadena "myProcessName":

Un trazador de líneas:

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

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

 96
Author: Eric Leschinski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-13 01:56:03

Si necesita más flexibilidad en la selección de los procesos use

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

Puede usar grep-e, etc.

 48
Author: Eugen Rieck,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-14 19:31:03

Puede usar el siguiente comando para listar el proceso

ps aux | grep -c myProcessName 

Si necesita verificar el recuento de ese proceso, ejecute

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

Después de lo cual puede matar el proceso usando

kill -9 $(ps aux | grep -e myProcessName | awk '{ print $2 }') 
 14
Author: Nived Thanima,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-21 07:25:35

También puedes usar killall -r my_pattern. -r Interprete el patrón de nombre de proceso como una expresión regular extendida.

killall -r my_pattern
 9
Author: Alex,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-26 08:47:39

Si juzgas pkill -f PATTERN un poco demasiado peligroso, escribí ezkill un script bash que te pide elegir qué procesos entre los que coinciden con el PATRÓN que quieres matar.

 7
Author: kraymer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-30 08:03:53

Puede usar el siguiente comando para

kill -9 $(ps aux | grep 'process' | grep -v 'grep' | awk '{print $2}')
 3
Author: Alex Liu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-11 10:51:20

Suena mal?

 pkill `pidof myprocess`

Ejemplo:

# kill all java processes
pkill `pidof java`
 2
Author: user6482587,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-14 14:32:03

Puede usar el siguiente comando para:

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

O

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

Funciona para mí.

 2
Author: Luis Lopes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-08 18:03:57

Si usted no quiere tomar dolor de cabeza de encontrar id de proceso, utilice regexp para matar proceso por nombre. Por ejemplo, para matar a Chrome siguiente código hará el truco.

killall -r --regexp chrome

 2
Author: ajaz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-16 07:39:40