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

来源:互联网 发布:怎么做淘宝虚拟充值 编辑:程序博客网 时间:2024/05/20 06:55

       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

 

原创粉丝点击