(12 risposte)
Chiuso 5 anni fa.
Ho bisogno di terminare un processo che contiene myName
nella sua descrizione. Attualmente sto facendo:
ps -ax |grep myName
I see PID
kill -9 PID
Come posso fare lo stesso con un comando senza inserire il PID?
Risposta accettata:
Se myName
è il nome del processo/eseguibile che vuoi eliminare, puoi usare:
pkill myName
pkill
per impostazione predefinita invia il SIGTERM
segnale (segnale 15). Se vuoi il SIGKILL
o segnale 9, usa:
pkilll -9 myName
Se myName
non è il nome del processo o, ad esempio, è un argomento per un altro comando (lungo), pkill
(o pgrep
) potrebbe non funzionare come previsto. Quindi devi usare -f
opzione. Da 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.
Quindi:
pkill -f myName
o
kill -9 $(pgrep -f myName)