I keep running these two commands over and over:
$ ps aux | grep php | grep -v grep
www-data 3663 100 14.8 328620 304900 ? R 12:56 0:54 php /home/jason/projects/mcif/./symfony import:process --id=91
jason@gob:~/projects/mcif$ sudo kill 3663
Is there a quick and easy way to just grab the pid and kill that? The closest I've come is this:
$ ps aux | grep php | egrep -o ' [0-9]+ ' | head -n1
3836
But I don't know how to pipe that through kill
.
pkill
will do what you're asking for here.Before you execute a
pkill
, try apgrep
first to make sure you're matching what you expect to be.You can also use "killall", which takes the name of a process and kills it. It takes the same args as kill.
You'd use "killall symfony" for your example.
A quick Google search for "ps grep kill" is indeed helpful:
http://www-mobile.ecs.soton.ac.uk/bjc97r/tips/kill-by-name.html
http://www.howtogeek.com/howto/ubuntu/kill-a-process-by-process-name-from-ubuntu-command-line/
http://www.commandlinefu.com/commands/view/1138/ps-ef-grep-process-grep-v-grep-awk-print-2-xargs-kill-9
I am using zap on OpenBSD (it is not on the base system).