shell脚本监控调度器/proc进程是否运行(嵌套循环)

/proc/<pid>/schedstat

$cat /proc/28733/schedstat

5726055470233 30451531 6336
First: time spent on the cpu, task->se.sum_exec_runtime,这个值与上面的se.sum_exec_runtime一样只是上面的除于1,000,000
Second:time spent waiting on a runqueue,这个值与上面的se.wait_sum一样
Third: of times run on this cpu, task->sched_info.pcount,这个值跟上面的se->nr_switches一样

se.sum_exec_runtime:       2843625.998498  //累计运行的物理时间时间
se.wait_sum       :            15.615407  //累计在就绪队列里的等待时间
#!/bin/bash


while [ 1 ]                     #监控进程一直做死循环操作

do
          for process_pid in $(ps aux|grep 1ea171ed |awk  '{print $2}'|grep -v 807)   #循环查找含"1ea171ed"的进程号

          do
                echo $process_pid

               pre_schedstat=`cat /proc/$process_pid/schedstat |awk  '{print $1}'`  #取 进程的 schedstat 相关数值
                echo $pre_schedstat

                  sleep 30
               last_schedstat=`cat /proc/$process_pid/schedstat |awk  '{print $1}'`   #取 30秒后进程的 schedstat 相关数值
                echo $last_schedstat

            if [ $pre_schedstat -eq $last_schedstat ];then         # 如果前后数值保持不变,则做kill -3 处理 
                      kill -3 $process_pid
                     echo " success kill dead process $process_pid "
             fi

          done
      sleep 60 

done 

猜你喜欢

转载自www.cnblogs.com/weifeng1463/p/9182940.html