您的位置:首页 > 其它

获取某个进程的CPU使用情况

2011-04-10 18:59 357 查看
Gain One Process Cpu Usage Info
First, top command to get all information
Then, grep command to get the process record that you want
Third,awk command to print out cpu info into file
The shell script file is attached here.

Use while sleep, get continuous cpu info of this process into log file.
And you have to use this script tool like this:
./getcpu.sh screen 2
#! /bin/bash

if [ $# -ne 2 ]
then

echo "Usage: $0 ProcessName InternalTime"
fi

Process=$1
Internal=$2

LogFile="Cpu.txt"

while sleep $Internal
do
top | grep $Process | awk '{ print $9, $10, $11}' >> $LogFile
done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: