timeout command in shell script!

Maarten Litmaath maart at cs.vu.nl
Tue Oct 3 16:00:41 AEST 1989


: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
: --------------------------- cut here --------------------------
PATH=/bin:/usr/bin:/usr/ucb
echo Extracting 'timeout'
sed 's/^X//' > 'timeout' << '+ END-OF-FILE ''timeout'
X#!/bin/sh
X# @(#)timeout 1.0 89/10/03 Maarten Litmaath
X
Xprog=`basename $0`
Xusage="Usage: $prog <timeout in seconds> <command>"
X
Xcase $1 in
X[0-9]*)
X	timeout=$1
X	shift
X	;;
X*)
X	echo "$usage" >&2
X	exit 2
Xesac
X
Xcase $# in
X0)
X	echo "$usage" >&2
X	exit 2
Xesac
X
Xexec 3>&2 2> /dev/null
X
Xtrap 'echo TIMEOUT >&3; exit 1' 1
Xtrap '' 14
X
Xsh -c '(sleep '$timeout'; kill -1 '$$'; kill -9 $$) & exec "$@" 2>&3' \
X	"$prog" "$@"
X
Xtrap '' 1
Xkill -14 -$$
X
Xexit 0
+ END-OF-FILE timeout
chmod 'u=rwx,g=rx,o=rx' 'timeout'
set `wc -c 'timeout'`
count=$1
case $count in
440)	:;;
*)	echo 'Bad character count in ''timeout' >&2
		echo 'Count should be 440' >&2
esac
exit 0
-- 
   Did Andy Tanenbaum get his programming   |Maarten Litmaath @ VU Amsterdam: 
instruction from a Cereal box?  (Sam McCrea)|maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.wizards mailing list