#!/bin/ksh
#
# Name: Runaway-Wrapper.sh
#
# Run a command but abort after N seconds of wall time
# if it's still running.
#
# Phil Ehrens <phil@slug.org>
#
command="/usr/local/bin/multimarkdown -t html"
typeset -f timeout=3
typeset -f poll_interval=0.1
$command $* |&
typeset -f i=0
while ps -p $! >/dev/null
do
sleep $poll_interval
((i+=$poll_interval))
if [[ $i -ge $timeout ]]
then
kill -5 $! >/dev/null
print -- "Aborted '$command $*' after $i seconds."
exit 13
fi
done
while read -p line
do
data="$data${line}\n"
done
print -- "$data"
exit 0