#!/bin/bash function usage() { echo "usage: timeout ..." echo "Runs the command with the args, but kills it if it runs for more than seconds." } case $# in 0|1) usage exit 1 ;; *) SECS=$1 shift esac PID=$$ { sleep $SECS kill $PID 2>/dev/null } & exec "$@" #"$@" & #PID=$! #{ # sleep $SECS # kill $PID 2>/dev/null #} & #KPID=$! #echo "waiting" #STAT=`wait $PID` #echo "cmd has terminated" #kill $KPID 2>/dev/null #exit $STAT