Pkill -f 不适用于进程杀伤

2022-08-30 19:08:43

我有这个进程运行:

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'

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


答案 1

尝试使用命令而不是kill

kill -9 <pid>

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

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

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

像这样循环如下图所示,作为我系统的精确工作副本;

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

我希望这最终会帮助你。

根据最新编辑的问题,您希望使用PHP运行此内容,可以通过命令实现,请按照问题进行解决。exec


答案 2

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

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

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

要终止进程,请首先搜索进程的进程 ID,然后对 PID 使用命令。喜欢PIDkill

$ 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 输出 4 中获取该过程的 PID。xargs sudo kill -9 : xargs 将逐个传递 PID 编号来杀死命令

推荐