Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
6  
This question title could be used for the entire history of humankind... –  gWaldo Nov 1 '10 at 17:56
    
There are days I feel the same way. –  Dennis Williamson Nov 1 '10 at 18:03
    
+1 for the title –  Joshua Enfield Nov 1 '10 at 21:17
add comment

4 Answers

up vote 7 down vote accepted

pkill will do what you're asking for here.

Before you execute a pkill, try a pgrep first to make sure you're matching what you expect to be.

share|improve this answer
    
sudo pkill php did it. Thanks. –  Jason Swett Nov 1 '10 at 17:17
add comment

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.

share|improve this answer
2  
Make a mental note though that if one day you use "killall" in a Solaris machine it will kill all active processes –  adamo Nov 1 '10 at 21:23
add comment

I am using zap on OpenBSD (it is not on the base system).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.