Pkill -f doesn't work for process killing
Asked Answered
A

3

25

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?

Aretta answered 13/11, 2014 at 5:39 Comment(0)
S
35

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.

Semanteme answered 13/11, 2014 at 5:52 Comment(4)
@Limzhenxiang check again, I have updated answer as per your new requirement.Semanteme
Had a similar problem (could not kill ruby process) when using pkill - using kill -9 worked perfectly -thanks!Hayes
@Skynet perhaps instead of ps|grep torrent| cut -f1 -d ; use pgrep -f torrent;Gospel
@Gospel that's also a good way, please post an answer for future readers.Semanteme
A
12

As you can see, the process are being run with screen command.

sh -c sudo screen /usr/bin/python
sudo screen /usr/bin/python
screen /usr/bin/python

Due to this you cannot kill the process with the command what you have used.

To kill the process, first search the PID process ID of the process and then use kill command with the PID. Like

$ kill -9 342

Also looking from your process list, it is visible that you have started the same process many times with different permission. So I suggest you kill all except one that is needed.

EDIT : This single command would suffice:

$ ps ax | grep 'Momomoko.E01.140011.HDTV.H264.720p.mp4' | awk -F ' ' '{print $1}' | xargs sudo kill -9

Here is what it does :

  1. ps ax : list the process
  2. grep : grep for the requred process name
  3. awk : to get only the PID's of the process from the grep ouput
  4. xargs sudo kill -9 : xargs will pass one by one PID number to kill command
Aurochs answered 13/11, 2014 at 6:0 Comment(1)
I don't see any major EDITS except for inclusion of kill-process tagAurochs
C
1

If you have that zombie process open in a terminal, you can Ctrl+z it, which on most shells lets the process run in the background and outputs something like:

[1]  + 69880 suspended  someprocess

You can then actually kill it with:

kill -9 69880

the same id that was shown when suspended.

Crain answered 26/7, 2018 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.