3 # Program: TimedExec.sh
5 # Synopsis: This script is a watchdog wrapper. It runs the specified program
6 # but times out if it does not complete in the allocated time frame.
7 # Syntax: ./TimedExec.sh <timeout> <dir> <program> <args...>
11 echo "./TimedExec.sh <timeout> <dir> <program> <args...>"
16 if [ "$1" = "-p" ]; then
17 PARENT
=$2; shift; shift;
24 if [ -z "$PARENT" ]; then
25 # Start a watchdog process
26 $0 -p $$
$TIMEOUT $
* &
30 # Sleep for a specified time then wake up to kill the parent process.
33 while [ $SEC -lt $TIMEOUT ]; do
35 # Check if parent has completed.
36 kill -0 $PARENT 2>/dev
/null
42 kill $PARENT && (sleep 2; kill -1 $PARENT) && (sleep 2; kill -9 $PARENT)