Pkill -f doesn't work for process killing

Lim zhen xiang picture Lim zhen xiang · Nov 13, 2014 · Viewed 31.2k times · Source

I have this process running:

342 pts/2    T    0:00 sh -c sudo screen /usr/bin/python /usr/bin/btdownloadcurses "http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent" --display_interval 20 --saveas "/srv/"
343 pts/2    T    0:00 sudo screen /usr/bin/python /usr/bin/btdownloadcurses http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent --display_interval 20 --saveas /srv/
344 pts/2    T    0:00 screen /usr/bin/python /usr/bin/btdownloadcurses http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent --display_interval 20 --saveas /srv/

I tried to run:

pkill -f http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent

But the process still running.
How do I force kill the processes that contain: "http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent" ?


Question as edited below:

ps ax | grep 'Momomoko.E01.140011.HDTV.H264.720p.mp4'

I want to kill all process that contain the above string.

I tried running the above line, and it returns three results:

  342 pts/2    T    0:00 sh -c sudo screen /usr/bin/python /usr/bin/btdownloadcurses "http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent" --display_interval 20 --saveas "/srv/Momomoko.E01.140011.HDTV.H264.720p.mp4"
  343 pts/2    T    0:00 sudo screen /usr/bin/python /usr/bin/btdownloadcurses http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent --display_interval 20 --saveas /srv/Momomoko.E01.140011.HDTV.H264.720p.mp4
  344 pts/2    T    0:00 screen /usr/bin/python /usr/bin/btdownloadcurses http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent --display_interval 20 --saveas /srv/Momomoko.E01.140011.HDTV.H264.720p.mp4

How do I run this line:

ps ax | grep 'Momomoko.E01.140011.HDTV.H264.720p.mp4'

..with php, and kill -9 all the matching processes?

Answer

Skynet picture Skynet · Nov 13, 2014

Try to use kill command rather

kill -9 <pid>

It will work for sure, cause I have tried it myself and very handy all times.

Use the following in a script file then run for loop with kill command,

ps|grep torrent|cut -f1 -d' '

like this for loop as shown below, as exact working copy from my system;

for p in `ps|grep torrent|cut -f1 -d' '`; do
   kill -9 $p
done

I hope this will help you finally.

As per latest edited question you want to run this with PHP, it can be implemented through exec command, please follow the question for solution.