linux top命令中是否有一个选项可以让我按名称过滤进程,并每隔1秒将该进程的CPU使用情况写入日志文件?
发布于 2014-01-14 19:28:21
#You can run following script as ./cpurecorder.sh pid filename
#It will generate output file with memory usage and cpu utilisation.
#You can log other variable by searching man for ps.
`enter code here`filepath=/home/rtcsadm # modify as desired
interval=20 # reports per minute
timelimit=6000 # how long to run, in seconds
mydate=`date "+%H:%M:%S"` # the timestamp
freq=$((60/$interval)) # for sleep function
while [ "$SECONDS" -le "$timelimit" ] ; do
ps -p$1 -opid -opcpu -opmem -ocomm -c | grep $1 | sed "s/^/$mydate /" >> $filepath/$2.txt
sleep 3
mydate=`date "+%H:%M:%S"`
done
https://stackoverflow.com/questions/8710584
复制相似问题