一 杀死指定进程
现知道有一个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很危险,使用须谨慎。