首页 > 其他 > 详细

shell 监控指定程序占用系统内存和CPU情况

时间:2014-02-09 16:47:01      阅读:375      评论:0      收藏:0      [点我收藏+]
#! /bin/bash
read -p "please input the thread name you want to monitor: " threadname
echo "name is $threadname"
read -p "please input the second you monitor: " second
filename=`date +%F`"log.txt";
echo "filename $filename"
#死循环
while true
do
#获得时间
MyTime=`date +%F%r`
#获得内存
MemInfo=`free -m|grep Mem|awk ‘{print " total: " $2,"use: "  $3,"free: " $4}‘`
MemInfo=${MyTime}${MemInfo}
echo $MemInfo >> $filename
#获得top命令监控信息
TopInfo=`top -b -n 1 |grep -w $threadname|awk ‘{print "\n"," cpu :",$9," mem: ",$10,$11,$12,"\n"}‘`
echo $TopInfo >> $filename
#睡眠时间
sleep $second
done


本文出自 “风清扬song” 博客,请务必保留此出处http://2309998.blog.51cto.com/2299998/1357406

shell 监控指定程序占用系统内存和CPU情况

原文:http://2309998.blog.51cto.com/2299998/1357406

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!