Linux/Runaway Process Control Wrapper

Bizen | Linux | Recent Changes | Preferences

#!/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

Bizen | Linux | Recent Changes | Preferences

Last edited May 16, 2012 10:06 am by Pokute
Search Bizen: