from:http://blog.chinaunix.net/uid-600330-id-2088714.html
#function : begin_timer HANDLER_NAME MICROSECONDS CMD_ON_TIMEOUT ARGS...
# @HANDLER_NAME : handler of timer
# @MICROSECONDS : micro seconds to wait
# @CMD_ON_TIMEOUT ARGS : command and its arguments to run when timeout
start_timer(){
[ $# -lt 2 ] && return 1
HANDLER=$1
TIMER=$2
shift 2
(
trap exit USR1
sleep $TIMER
"$@"
)&
eval export $HANDLER=$!
}
export -f start_timer
(more...)