Reputation: 32776
I'm trying to setup a task to kill certain server processes when the server gets into a weird state such as when it fails to boot one process, but another process gets keeps running and so not everything boots up. This is mainly a task for development so you can do jake killall
to kill all processes associated with this project.
I'm having trouble figuring out how to get the pid
after doing: ps aux | grep [p]rocess\ name | {HOW DO I GET THE PID NOW?}
and then after getting the ID how do I pass that to kill -9 {PID HERE}
Upvotes: 0
Views: 177
Reputation: 4750
You could also you killall <program>
or pkill <program>
or pgrep <program>
Upvotes: 2
Reputation: 290255
The PID is the second column, so you can do
ps aux | grep [p]rocess\ name | awk '{print $2}'
All together,
my_pid=$(ps aux | grep [p]rocess\ name | awk '{print $2}')
kill -9 $my_pid
Upvotes: 2