system
system copied to clipboard
Get CPU usage may error
If proc id is in another process cmd line, grep may find it.
//返回某个进程的cpu使用率
func CpuUsedRateByProc(proc string) string {
//return ExecOutput("ps axuwww|grep " + proc + "|grep -v grep|awk 'BEGIN{sum=0}{sum+=$3 }END{print sum}'")
return ExecOutput("top -n 1 -b |grep '"+proc+"'|grep -v grep|awk 'BEGIN{sum=0}{sum+=$9 }END{print sum}'")
}