






















2011-12-26 16:02 Jeff 阅读(11743) 评论() 收藏 举报
网上找了个例子,简单实用如下. 可以有一个后台进程,在timer超时采取一些操作.
#!/bin/ksh
#Delaytime=0
AlarmHandler()
{
echo "Get SIGALAM"
KillSubProcs
exit 14
}
KillSubProcs()
{
#kill cbm
echo "it's time out,kill cbm here"
if [ $? -eq 0 ];then
echo "Sub-processes killed."
fi
}
SetTimer()
{
Delaytime=$1
echo $Delaytime
if [ $Delaytime -ne 0 ];then
sleep $Delaytime && kill -s 14 $$ &
#CHPROCIDS="$CHPROCIDS $!"
TIMERPROC=$!
fi
}
UnsetTimer()
{
echo "Start to unset timer"
kill $TIMERPROC
}
trap AlarmHandler 14
SetTimer 30
#CHPROCIDS="$CHPROCIDS $!"
#wait $!
sleep 40
UnsetTimer
echo "ALL Done."
exit 0
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。