网上找了个例子,简单实用如下. 可以有一个后台进程,在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

相关文章:

  • 2021-12-05
  • 2021-12-05
  • 2022-01-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-05
  • 2021-12-28
  • 2022-12-23
  • 2021-12-18
  • 2021-08-29
相关资源
相似解决方案