首页 > 系统服务 > 详细

Linux kill 杀死指定进程

时间:2016-01-13 12:42:40      阅读:142      评论:0      收藏:0      [点我收藏+]

一  杀死指定进程

现知道有一个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 curl | grep -v php | cut -c 15-20
 28367
leo@localhost$ ps -ef | grep php | grep -v grep | cut -c 15-20 | 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很危险,使用须谨慎。

Linux kill 杀死指定进程

原文:http://www.cnblogs.com/maowenqiang/p/5126792.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!