赞
踩
个人随笔 (Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
下面是两个shell脚本程序,算是常用到的两个脚本形式,记录下来,供参考使用。
一个是监控进程cpu与mem占用的;
一个是启动多进程,为程序传递不同数字参数的;
#!/bin/sh
procname=systemd
delay=30
while true
do
# get pid from system
pid=`ps -ef|grep ${procname}|grep -v grep|head -n 1|awk -F' ' '{print $2}'`
# get process info from top command
#echo "top -n 1 -b -p ${pid} "
top -n 1 -b -p ${pid}|awk -F'\n' '$1+0>0 {print strftime("%Y-%m-%d_%H:%M:%S"),$0; fflush();}'|tee -a top.log
# delay a few seconds
sleep ${delay}
done
启动多个进程,监控不同的id范围
#!/bin/sh
func=./trace
for i in $(seq 1 20)
do
# calc startid and endid
startid=`expr $i \* 5000`
endid=`expr $startid + 5000`
# start process
echo "$func $startid $endid > ${i}.log"
$func $startid $endid >${i}.log &
done
个人随笔 (Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。