kill杀掉超过24小时的进程
#!/bin/bash
function check_time()
{
time_subroutine=$(getconf CLK_TCK)
start_time=$(awk '{print $22}' /proc/$1/stat)
sys_uptime=$(awk '{print $1}' /proc/uptime)
pid_uptime=$((${sys_uptime%.*} - ${start_time}/${time_subroutine}))
if [ ${pid_uptime} -ge 86400 ];then
kill $1
fi
}
for pid in `ps -A | grep "chromedriver"|awk '{print $1}'`
do
check_time $pid
done
只保留最近十个进程
ps aux --sort=-start_time | grep TestTask | tail -n +11 | awk '{print $2}' | xargs kill -9
--sort=-start_time //按照进程开始时间由近到远排序
grep TestTask //筛选指定的进程
tail -n +11 //由第十一个进程开始取值,即保留最近的十个进程
awk '{print $2}' //输出pid
xargs kill -9 //批量传参、kill掉进程