shell判断进程启动时间后kill进程
#!/bin/bash#检测"API_NetDemo"进程运行时间超过10分钟就kill掉
#PS:是程序运行时间(即进程启动到现在的时间),不是占用cpu的时间
#Author by Qfeian
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 600 ];then
kill -9 $1
fi
}
#for pid in $(ps -A -o pid,start_time,etime,comm | grep "API_NetDemo")
for pid in `ps -A | grep "API_NetDemo"|awk '{print $1}'`
do
check_time $pid
done
页:
[1]