19

我正在运行这个过程:

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/

我试图运行:

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

但进程仍在运行。
如何强制终止包含以下内容的进程:“ http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent ”?


问题编辑如下:

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

我想杀死所有包含上述字符串的进程。

我尝试运行上面的行,它返回三个结果:

  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

我如何运行这一行:

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

..with php,以及kill -9所有的匹配过程?

4

3 回答 3

23

尝试使用kill命令而不是

kill -9 <pid>

它肯定会起作用,因为我自己尝试过,而且一直非常方便。

kill在脚本文件中使用以下内容,然后使用命令运行 for 循环,

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

如下所示的 for 循环,作为我系统中的确切工作副本;

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

我希望这最终会对你有所帮助。

根据最新编辑的问题,您想用 PHP 运行它,它可以通过exec命令实现,请按照问题解决。

于 2014-11-13T05:52:12.440 回答
8

如您所见,该过程正在使用 screen 命令运行。

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

因此,您无法kill使用您使用过的命令进行处理。

要杀死进程,首先搜索进程的PID进程 ID,然后使用kill带有 PID 的命令。喜欢

$ kill -9 342

从您的进程列表中也可以看出,您已经多次使用不同的权限启动了相同的进程。所以我建议你杀掉所有需要的东西。

编辑: 这个单一的命令就足够了:

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

这是它的作用:

  1. ps ax : 列出进程 2. grep : grep 获取所需的进程名称 3. awk : 从 grep 输出中仅获取进程的 PID 4. xargs sudo kill -9 : xargs 将一个一个传递 PID 号以杀死命令
于 2014-11-13T06:00:34.430 回答
1

如果你在终端中打开了那个僵尸进程,你可以Ctrl+z这样做,在大多数 shell 上,它可以让进程在后台运行并输出如下内容:

[1]  + 69880 suspended  someprocess

然后,您实际上可以使用以下方法杀死它:

kill -9 69880

暂停时显示的相同 ID。

于 2018-07-26T19:31:48.470 回答