(12 réponses)
Fermé il y a 5 ans.
J'ai besoin de tuer un processus qui contient myName
dans son descriptif. Actuellement je fais :
ps -ax |grep myName
I see PID
kill -9 PID
Comment puis-je faire la même chose avec une seule commande sans entrer le PID ?
Réponse acceptée :
Si myName
est le nom du processus/exécutable que vous voulez tuer, vous pouvez utiliser :
pkill myName
pkill
envoie par défaut le SIGTERM
signal (signal 15). Si vous voulez le SIGKILL
ou signal 9, utilisez :
pkilll -9 myName
Si myName
n'est pas le nom du processus ou, par exemple, est un argument d'une autre commande (longue), pkill
(ou pgrep
) peut ne pas fonctionner comme prévu. Vous devez donc utiliser le -f
option. De man kill
:
-f, --full
The pattern is normally only matched against the process name.
When -f is set, the full command line is used.
NOTES
The process name used for matching is limited to the 15 characters present
in the output of /proc/pid/stat. Use the -f option to match against the
complete command line, /proc/pid/cmdline.
Donc :
pkill -f myName
ou
kill -9 $(pgrep -f myName)