网上找了个例子,简单实用如下. 可以有一个后台进程,在timer超时采取一些操作.
#!/bin/ksh#Delaytime=0AlarmHandler(){echo "Get SIGALAM"KillSubProcsexit 14}KillSubProcs(){#kill cbmecho "it's time out,kill cbm here"if [ $? -eq 0 ];thenecho "Sub-processes killed."fi}SetTimer(){Delaytime=$1echo $Delaytimeif [ $Delaytime -ne 0 ];thensleep $Delaytime && kill -s 14 $$ &#CHPROCIDS="$CHPROCIDS $!"TIMERPROC=$!fi}UnsetTimer(){echo "Start to unset timer"kill $TIMERPROC}trap AlarmHandler 14SetTimer 30#CHPROCIDS="$CHPROCIDS $!"#wait $!sleep 40UnsetTimerecho "ALL Done."exit 0