shell scripting, how to auto-timeout?

Nerius Landys nlandys at gmail.com
Fri Jan 23 15:04:56 PST 2009


I decided that I want the exec line at the end of the script because I
want the exit code of the script to be the exit code of the Java
process.  I'm willing to live with the fact that the sleep thread will
wait its full 3 seconds. So my final script is this:

#!/bin/sh

cd `dirname "$0"`
CLASSPATH="mapgen.jar"
export CLASSPATH

THIS_SCRIPT_PROCESS="$$"
sleep 3 && kill "$THIS_SCRIPT_PROCESS" > /dev/null 2>&1 && \
  echo "Terminated infinite looping." 1>&2 &
#SLEEP_PROCESS="$!"

exec /usr/local/bin/java $*


More information about the freebsd-questions mailing list