这里用脚本实现了一个极为简单的top命令。为了演示方便,我们在脚本中将很多参数都写成硬代码,你可以根据需要更换这些参数,或者用更为灵活的方式替换现有的实现。
[root@xieqichao ~]
header=`ps aux | head -n 1`
while :
do
clear
uptime
echo "$header"
ps aux | sed -e 1d | sort -k3nr -k1,1 -k2n | head -n 20
sleep 5
done
CTRL+D
[root@xieqichao ~]
21:55:07 up 13:42, 2 users, load average: 0.00, 0.00, 0.00
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 6408 2.0 0.0 4740 932 pts/2 R+ 21:45 0:00 ps aux
root 1755 0.2 2.0 96976 21260 ? S 08:14 2:08 nautilus
68 1195 0.0 0.4 6940 4416 ? Ss 08:13 0:00 hald
postfix 1399 0.0 0.2 10312 2120 ? S 08:13 0:00 qmgr -l -t fifo -u
postfix 6021 0.0 0.2 10244 2080 ? S 21:33 0:00 pickup -l -t fifo -u
root 1 0.0 0.1 2828 1364 ? Ss 08:12 0:02 /sbin/init
... ...