:
#
# Usage: $0 seconds command....
# Run a command for at most the specified amount of time. 

ECHO=echo
TEST=test
SHELL=/bin/sh
SLEEP=/bin/sleep
KILL=/bin/kill
SETSID=

# If we have setsid, run the command in a separate process group and
# kill the whole group when time runs out.

test -n "$SETSID" && vic=0

case $# in
0|1) $ECHO "usage: $0 seconds command..." 1>&2; exit 1;;
  *) timeout=$1; shift
     exec $SETSID $SHELL -c "
	 ($SLEEP $timeout; $KILL -9 ${vic-$$} 2>/dev/null) >/dev/null &
	 exec $*
     ";;
esac
