• 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很危险,使用须谨慎。

  • 相关阅读:
    软件开发模式
    个人中心设计
    定制四则运算
    功能测试用例分析报告
    NABCD
    开发流程
    开发流程
    结对编程
    注册界面进行Toast提示
    登录注册页面修改错误
  • 原文地址:https://www.cnblogs.com/maowenqiang/p/5126792.html
Copyright © 2020-2023  润新知