检测系统中进程占满单个cpu的情况

#!/bin/bash
function thread_used_cpu(){
    # $1 为单个cpu负载的百分比
    if [[  $1 == ""  ]];then
       full_load_percent=95
    else
       full_load_precent=$1
    fi
    ps_info=(`ps H -eo pid|uniq -c|grep -v 'PID'|awk '{ if ($1==1) print $2}'`)
    echo ${ps_info[@]}|grep '5350'
    grep_string=$(echo ${ps_info[@]}|sed 's/ /\|/g')
    echo "`ps H -eo pid,psr,pcpu,comm,tid |grep -E ${grep_string}|awk -v full_load_percent=$full_load_percent '{ if ($3 > full_load_percent) print "pid:"$1",核心号:"$2",cpu使用率:"$3",进程名称:"$4",线程id:"$5; else print "None" }'`"
}
thread_used_cpu
    
posted @ 2019-09-24 10:07  random_lee  阅读(371)  评论(0编辑  收藏  举报