maart@cs.vu.nl (Maarten Litmaath) (02/24/90)
--------------------cut here-------------------- #!/bin/sh # @(#)timeout 6.1 90/02/24 Maarten Litmaath prog=`basename $0` usage="Usage: $prog [-signal] [timeout] [:interval] [+delay] [--] <command>" SIG=-KILL # default signal sent to the process when the timer expires, # unless a delay option has been given: then it is -TERM sigopt=0 timeout=60 # default timeout interval=15 # default interval between checks if the process is still alive finish=: while : do case $1 in --) shift break ;; -*) SIG=$1 sigopt=1 ;; [0-9]*) timeout=$1 ;; :*) EXPR='..\(.*\)' interval=`expr x"$1" : "$EXPR"` ;; +*) EXPR='..\(.*\)' delay=`expr x"$1" : "$EXPR"` finish="kill -0 $$ && sleep $delay && kill -KILL $$" case $sigopt in 0) SIG=-TERM esac ;; *) break esac shift done case $# in 0) echo "$usage" >&2 exit 2 esac ( sleep $timeout & timer=$! ( while kill -0 $$ do sleep $interval done kill -9 $timer ) & check=$! wait $timer kill $SIG $$ && eval "$finish" kill -9 $check ) 2> /dev/null & exec "$@" --------------------cut here-------------------- -- "Belfast: a sentimental journey to the Dark Ages - Crusades & Witchburning - Europe's Lebanon - Book Now!" | maart@cs.vu.nl, uunet!mcsun!botter!maart