Home

zhangyiqun

Thoughts, stories and ideas.

Research 2014年以前 スーパーマリオ 关于

28 Apr 2009
shell面试题一个,对比小数大小

帮朋友写的,功能是监视top中的cpu使用,这题比较冷门的是shell中小数的对比。

#!/bin/bash
while :
do
top -d 30 -b -n 1 > /root/top1
top -d 60 -b -n 1 > /root/top2
BEFORE=`awk 'NR==3{print $2}' /root/top1 | sed -n 's/[^0-9.]//gp'`
AFTER=`awk 'NR==3{print $2}' /root/top2 | sed -n 's/[^0-9.]//gp'`
expr $BEFORE \> $AFTER &>/dev/null
if (( $? == 1 ))
then
        echo $AFTER>/tmp/now
fi && break
done
exit 0

Research 2014年以前 スーパーマリオ 关于