#!/bin/sh
while :
do
stillRunning=$(ps |grep "test" |grep -v "grep")
if [ "$stillRunning" ] ; then
echo "test service was already started by another way"
else
echo "Starting service ..."
/flash/test &
echo "test service was exited!"
fi
sleep 5
while :
do
stillRunning=$(ps |grep "test" |grep -v "grep")
if [ "$stillRunning" ] ; then
echo "test service was already started by another way"
else
echo "Starting service ..."
/flash/test &
echo "test service was exited!"
fi
sleep 5
done
ps |grep "test" |grep -v "grep"语句是查询test程序是否运行,若在运行,则返回非0
这是每5秒查询一次test是否退出运行了。
附带说一句,arm板的自启动脚本在 etc/init.d/rcS里面,一般可以将想开机运行的程序放在里面,但是记住,
不要将你写的脚本放到里面。否则下次断电重启,你的arm板启动到最后可能起不来。
如何解决希望开机就启动自己的一个脚本呢? 可以写一个程序 用system来执行脚本,然后将这个程序放到开机自启动里面就行了。
也就是开机自启动程序,程序启动脚本。
char cmd[20]=“/flash/restart.sh”;
system(cmd);