shell獲取執行超過1天時間的程序
阿新 • • 發佈:2019-02-10
#!/bin/bash
sys_uptime=$(cat /proc/uptime | cut -d" " -f1);
user_hz=$(getconf CLK_TCK) ;
for pid in `ps -ef | grep "/usr/local/php/bin/php"| grep -v "grep" | awk '{print $2}'`;do
pid_uptime=$(cat /proc/$pid/stat | cut -d" " -f22);
last_time=$((${sys_uptime%.*}-$pid_uptime/$user_hz ));
#echo $pid "execute time of " $last_time "second";
if [ $last_time -gt 86400 ];then
#echo $pid "execute time is over 3600 seconds"
#ps -ef | grep $pid| grep -v "grep"
#kill $pid -9
fi
done
/usr/local/php/bin/php改為你要過濾的程序
由time子例程返回的每秒鐘時鐘計數,32位和64不一樣