3

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.

Jason Swett
  • 1,468
  • 5
  • 23
  • 37

4 Answers4

7

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.

mark
  • 2,365
  • 14
  • 11
2

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.

Edwin Knuth
  • 31
  • 1
  • 3
  • 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 01 '10 at 21:23
0

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

adamo
  • 6,925
  • 3
  • 30
  • 58