文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一道很好的Shell编程题

一道很好的Shell编程题

时间:2009-05-09  来源:bestilyq

    最近在网上浏览到一个对于Shell编程题的讨论,因为感觉这个题目很好,所以整理如下:

请编写一个标准Shell脚本testd,实现如下功能:
A、在Linux操作系统启动的时候,自动加载/mnt/test/test程序。
B、当test退出之后,自动重新启动。
C、当test程序重启次数超过100次,自动复位操作系统。
假设你所拥有的资源:
A、目标机器是一台具有标准shell的嵌入式计算机,CPU为ARM7 56MB,内存16MB,软件环境基于Linux2.6.11和BusyBox1.2构建。
B、当前已有11个用户进程在运行,占用了大部分的CPU时间和内存,你可使用的内存只有2MB左右,CPU时间由系统分派。
(本题满分20分,程序15分,注释5分。程序不能运行的0分,能够运行但有BUG的10分,能够正确无误的运行的15分。清楚编写注释的5分。)

参考答案:
########################################
#testd is a daemon script to start and watch the program test
########################################
#!/bin/sh

#load *.so that may need
if [ -r /sbin/ldconfig ]; then
ldconfig
fi

#add the libs PATH that may need
export LD_LIBRARY_PATH="/lib"

#count is a counter of test running times
count=0

#main loop
while [ 1 ] ;do
#add execute attribute to /mnt/test/test
chmod +x /mnt/test/test
#launch test
/mnt/test/test
#the running times counter
let count=count+1
echo "test running times is $count"
#Is test runs too many times?
if [ "$count" -gt 100 ]; then
echo "Will reboot when test runs too many times"
reboot
fi
#waiting for test stop...
sleep 3
done
#########################################

最后,在init里加载这个脚本,实现系统启动时自动加载的功能。
相关阅读 更多 +
排行榜 更多 +
味子夫

味子夫

购物比价 下载
恩猫

恩猫

购物比价 下载
街头纷争

街头纷争

动作格斗 下载