码迷,mamicode.com
首页 > 系统相关 > 详细

Linux kill 杀死指定进程

时间:2016-01-13 12:43:31      阅读:147      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!