#!/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改为你要过滤的进程
lasttime−gt86400这里是秒数,可以改为3600,也就是1个小时userhz=
(getconf CLK_TCK) ;
由time子例程返回的每秒钟时钟计数,32位和64不一样