日期:2014-05-16 浏览次数:20762 次
#!/bin/sh
if [ "$#" -ne "1" ];then
echo "usage: $0 <process name>"
exit 1
fi
pid=`pgrep $1 | awk '{print $1}'`
top -b -n 1 -p $pid | awk '$1=="PID"{print $5,$6,$7}'
top -b -d 2 -p $pid | awk -v awk_pid="$pid" '$1==awk_pid{print $5,$6,$7}'
top -b -d 2 -p $pid
------解决方案--------------------
awk -v awk_pid="$pid" '$1==awk_pid{print $5,$6,$7;fflush()}'