Linux shell

来源:互联网 发布:域名备案有什么影响 编辑:程序博客网 时间:2024/06/05 09:01

1、请编写一个标准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时间由系统分派。

本题是考查LINUX和嵌入式编程功底的,写出程序来的不少,但是95%以上的人竟无视我假设的资源,不知道在重启test程序的时候需要加上一个适当的掩饰时间,以便资源紧张的操作系统有时间回收资源。85%的人不知道写完testd之后,要在init里边加载这个脚本,才能实现启动时自动加载的功能。有人甚至在脚本开头使用bash作为脚本解析器,我已经清清楚楚说明了用“标准shell”!用sh不就完了吗?是习惯作祟吗?

#########################################testd is a daemon script to start an watch the program test#########################################!/bin/sh#load *.so that may needif [ -r /sbin/ldconfig ]; thenldconfigfi#add the libs PATH that may needexport LD_LIBRARY_PATH="/lib"#count is the counter of test started timescount=0#main loopwhile [ 1 ] ;do#add execute property for /mnt/test/testchmod +x /mnt/test/test#start test/mnt/test/test#the running times counterlet count=count+1echo "test running times is $count"#Is test running too many times?if [ "$count" -gt 100 ]; thenecho "Will reboot because of test running too many times"rebootfi#wait for test stoping...sleep 3done#########################################


 

原创粉丝点击