Pkill -f不适用于进程终止

Lim*_*ang 12 php linux termination kill-process pkill

我正在运行此进程:

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/
Run Code Online (Sandbox Code Playgroud)

我试着跑:

pkill -f http://zoink.it/torrent/732A4A9B54B7E3A916C2835D936D985942F65A6D.torrent
Run Code Online (Sandbox Code Playgroud)

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


编辑如下:

ps ax | grep 'Momomoko.E01.140011.HDTV.H264.720p.mp4'
Run Code Online (Sandbox Code Playgroud)

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

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

  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
Run Code Online (Sandbox Code Playgroud)

我该如何运行这一行:

ps ax | grep 'Momomoko.E01.140011.HDTV.H264.720p.mp4'
Run Code Online (Sandbox Code Playgroud)

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

Sky*_*net 12

尝试使用kill命令

kill -9 <pid>
Run Code Online (Sandbox Code Playgroud)

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

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

ps|grep torrent|cut -f1 -d' '
Run Code Online (Sandbox Code Playgroud)

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

for p in `ps|grep torrent|cut -f1 -d' '`; do
   kill -9 $p
done
Run Code Online (Sandbox Code Playgroud)

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

  • @Skynet 也许代替 ps|grep torrent| 切-f1-d;使用 pgrep -f 种子; (3认同)

San*_*h A 8

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

sh -c sudo screen /usr/bin/python
sudo screen /usr/bin/python
screen /usr/bin/python
Run Code Online (Sandbox Code Playgroud)

因此,您无法kill使用命令处理所使用的内容.

要终止进程,首先搜索PID进程的进程ID,然后使用kill带有PID的命令.喜欢

$ **kill -9 342**
Run Code Online (Sandbox Code Playgroud)

从流程列表中可以看出,您可以使用不同的权限多次启动相同的流程.所以我建议你除了一个需要的东西之外杀死所有人.

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

$ ps ax | grep 'Momomoko.E01.140011.HDTV.H264.720p.mp4' | awk -F ' ' '{print $1}' | xargs sudo kill -9
Run Code Online (Sandbox Code Playgroud)

这是它的作用:

  1. ps ax:列出进程
  2. grep:grep表示所需的进程名称
  3. awk:从grep输出中仅获取进程的PID
  4. xargs sudo kill -9:xargs会逐个传递一个PID号来杀死命令