• Linux kill 杀死指定进程


    一  杀死指定进程

    现知道有一个php线程正在运行,需要杀死

    root 26278 1 0 2015 ? 00:00:31 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php
    root 26280 1 0 2015 ? 00:00:34 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php

    ps -ef 查询运行进程

    leo@localhost$ ps -ef | grep php

    root 26278 1 0 2015 ? 00:00:31 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php
    root 26280 1 0 2015 ? 00:00:34 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php

    ps -ef 查询并过滤进程id:

    leo@localhost$ ps -ef | grep php

    root 26278 1 0 2015 ? 00:00:31 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php
    root 26280 1 0 2015 ? 00:00:34 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php

    leo@localhost$ ps -ef | grep php | grep -v grep | cut -c 15-20

     26280
     26280

    ps -ef 查询并过滤进程id,并杀死该进程:

    leo@localhost$ ps -ef | grep php
    root 26278 1 0 2015 ? 00:00:31 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php  (杀死进程前)
    root 26278 1 0 2015 ? 00:00:31 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php
    leo@localhost$ ps -ef | grep daemon_login.php | grep -v grep | cut -c 9-15
     28367
    leo@localhost$ ps -ef | grep daemon_login.php | grep -v grep | cut -c 9-15 | xargs kill -9
    leo@localhost$ ps -ef | grep php
    root 26278 1 0 2015 ? 00:00:31 /usr/local/php/bin/php /var/www/html/redis/daemon/daemon_register.php (杀死进程后,无此进程)

    或者: 

    kill   -9   `ps   -ef|grep   “processname” | grep -v "grep"|awk   '{print   $2} '`

    二 杀死批量进程

    for pid in $(ps -ef | grep curl | grep -v grep | cut -c 15-20); do    (获取进程id数组,并循环杀死所有进程)
        echo $pid
        kill -9 $pid
    done

    劝君一句:kill很危险,使用须谨慎。

  • 相关阅读:
    iOS7以上自定义一个navigationController,并沿用系统的侧滑返回效果
    判断一个日期是否再某个日期范围内object-c 范例
    统计软件简介
    大学生对vivo手机的看法
    第二次作业,制作调查问卷
    作业一:数据软件系统的介绍及spss的操作简介
    Android WebView
    Android ListView
    ARM和x86
    android shape和selector
  • 原文地址:https://www.cnblogs.com/maowenqiang/p/5126792.html
Copyright © 2020-2023  润新知