diff options
author | Jari Aalto <jari.aalto@cante.net> | 1998-04-17 19:52:44 +0000 |
---|---|---|
committer | Jari Aalto <jari.aalto@cante.net> | 2009-09-12 16:46:51 +0000 |
commit | cce855bc5b117cb7ae70064131120687bc69fac0 (patch) | |
tree | 39c7a4ec8f6d22ef03df74f2684e6a04fef10399 /examples/scripts/timeout | |
parent | e8ce775db824de329b81293b4e5d8fbd65624528 (diff) | |
download | android_external_bash-cce855bc5b117cb7ae70064131120687bc69fac0.tar.gz android_external_bash-cce855bc5b117cb7ae70064131120687bc69fac0.tar.bz2 android_external_bash-cce855bc5b117cb7ae70064131120687bc69fac0.zip |
Imported from ../bash-2.02.tar.gz.
Diffstat (limited to 'examples/scripts/timeout')
-rw-r--r-- | examples/scripts/timeout | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/examples/scripts/timeout b/examples/scripts/timeout new file mode 100644 index 0000000..ac8d88f --- /dev/null +++ b/examples/scripts/timeout @@ -0,0 +1,53 @@ +#Newsgroups: comp.unix.admin,comp.unix.solaris,comp.unix.shell +#From: gwc@root.co.uk (Geoff Clare) +#Subject: Re: timeout -t <sec> <unix command> (Re: How to give rsh a shorter timeout?) +#Message-ID: <EoBxrs.223@root.co.uk> +#Date: Fri, 13 Feb 1998 18:23:52 GMT + +# +# Conversion to bash v2 syntax done by Chet Ramey <chet@po.cwru.edu +# UNTESTED +# + +prog=${0##*/} +usage="usage: $prog [-signal] [timeout] [:interval] [+delay] [--] <command>" + +SIG=-TERM # default signal sent to the process when the timer expires +timeout=60 # default timeout +interval=15 # default interval between checks if the process is still alive +delay=2 # default delay between posting the given signal and + # destroying the process (kill -KILL) + +while : +do + case $1 in + --) shift; break ;; + -*) SIG=$1 ;; + [0-9]*) timeout=$1 ;; + :*) EXPR='..\(.*\)' ; interval=`expr x"$1" : "$EXPR"` ;; + +*) EXPR='..\(.*\)' ; delay=`expr x"$1" : "$EXPR"` ;; + *) break ;; + esac + shift +done + +case $# in +0) echo "$prog: $usage" >&2 ; exit 2 ;; +esac + +( + for t in $timeout $delay + do + while (( $t > $interval )) + do + sleep $interval + kill -0 $$ || exit + t=$(( $t - $interval )) + done + sleep $t + kill $SIG $$ && kill -0 $$ || exit + SIG=-KILL + done +) 2> /dev/null & + +exec "$@" |