shell获取执行超过1天时间的进程

#!/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改为你要过滤的进程
lasttimegt8640036001userhz= (getconf CLK_TCK) ;
由time子例程返回的每秒钟时钟计数,32位和64不一样

猜你喜欢

转载自blog.csdn.net/bwlab/article/details/78784567
今日推荐