Looking to use kill -9
instead of killall
using process name.
Is there a way I can grep
or awk
the pid of a given process name/s then kill it will kill -9
?
killall
fails a lot for me.
I'm looking to script this for numerous remote machines.
Process name will be one of three.
I want to use something like:
sshpass -p 'password' ssh -n $user@$hostname "one liner to use kill -9"
Any ideas?
The
-9
argument you mentioned specifies the signalkill
shall send to the process in question. The default is SIGTERM (terminate application), 9 is equivalent to SIGKILL (kill the application immediately and most brutally).killall
accepts signal arguments (like-9
or-KILL
, I prefer the symbolic names over numbers) too:Alternatively, there is
pkill
, which kills processes that match a given command pattern, which accepts signal arguments just as well. You can "preview" what would be killed by it usingpgrep -a
, which lists the matching progresses instead of sending a signal and killing them:If you want to match your pattern against the whole command including its arguments and not just the base command, add the
-f
switch:For more information, check the relevant manual pages:
man kill
,man killall
,man pkill
for the various kill commands andman 7 signal
for an overview of available signals.