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
10 answers
Use pkill -f
, que coincide con el patrón para cualquier parte de la línea de comandos
pkill -f my_pattern
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
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.
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 }')
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
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.
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}')
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`
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í.
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
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