【问题标题】:Pkill -f doesn't work for process killingPkill -f 不适用于进程终止
【发布时间】:2015-01-10 04:43:31
【问题描述】:

我正在运行这个进程:

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 的所有匹配进程?

【问题讨论】:

    标签: php linux kill-process termination pkill


    【解决方案1】:

    尽量使用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命令实现,请按照question解决。

    【讨论】:

    • @Limzhenxiang 再次检查,我已根据您的新要求更新了答案。
    • 在使用 pkill 时遇到了类似的问题(无法杀死 ruby​​ 进程)-使用 kill -9 效果很好-谢谢!
    • @Skynet 也许代替 ps|grep torrent|剪切 -f1 -d ;使用 pgrep -f torrent;
    • @mtnpaul 这也是一个好方法,请为未来的读者发布答案。
    【解决方案2】:

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

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

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

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

    $ 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号传递给kill命令

    【讨论】:

    • 我没有看到任何主要的EDITS 除了包含kill-process 标签
    【解决方案3】:

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

    [1]  + 69880 suspended  someprocess
    

    然后你可以真正杀死它:

    kill -9 69880
    

    与暂停时显示的 ID 相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-02
      • 2017-03-23
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 2016-04-16
      • 2022-01-11
      • 1970-01-01
      相关资源
      最近更新 更多