1、ps -ef | grep async_script | grep -v grep | awk '{print $2}'
async_script 为要查找的进程名
awk 依次对每一行进行处理,并输出
正常输出为多个类似于下面的输出:
root 23115 1 0 4月25 ? 00:00:01 php /mydata/data/dc_leba_new/async_script/script_first_ranking.php
因此$2就是进程id
2、pgrep -f async_script
最简单的方法是使用pgrep,输出的效果和方法1一样
3、如果想批量kill掉查找出的进程
pkill -f async_script
4、php脚本执行系统命令批量kill进程
1、直接的方法
exec('pkill -f async_script');
2、先查找再kill
$sh = 'pgrep -f async_script';
exec($sh, $res, $rc);
if($rc == 0 && !empty($res)){
foreach($res as $val){
exec('kill -9 '.$val);
}
}
根据进程名获取进程id,批量杀死进程
猜你喜欢
转载自blog.csdn.net/raoxiaoya/article/details/92373409
今日推荐
周排行