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 |