0

I have two instances of ffserver running both using different configuration file kept at different path. I want to kill one of them using a script. when i write following command :

    ps -ef |grep ffs

it gives output :

    root      6421  6394  0 18:47 pts/11   00:00:00 /root/bin/ffserver -f /root/newff/ffserver.conf
    root      6575  6562  0 18:49 pts/11   00:00:02 /root/bin/ffserver -f /root/test/downloaded/complete/ffserver.conf
    root      8453  3720  0 19:09 pts/11   00:00:00 grep ffs

Now i want to kill only one . Is there any way to kill using command name like i can give command name with kill

   pkill_like_command /root/bin/ffserver -f /root/newff/ffserver.conf

Please tell me how to do that as simple pkill will not work.

GP007
  • 691
  • 2
  • 9
  • 24

1 Answers1

0

There is an -f switch that works for pkill, so that matching considers the full command line. You can test without killing using pgrep instead. So the command line would be for example (tested on Debian with procps 1:3.2.8-9):

pkill -f "ffserver.*/root/newff/ffserver.conf"

without pkill:

kill $( ps -ef | grep "ffserver.*/root/newff/ffserver.conf" | awk '{ print $2 }' )
Michael Jaros
  • 4,586
  • 1
  • 22
  • 39