Steffen Nurpmeso wrote in <20190803224008.dvnlu%stef...@sdaoden.eu>: ... |wanted to add a reaper process which automatically kills tests |which need longer than X seconds. That turns out to be more .. | echo shell is $SHELL/$0 | ( | int= hot= | echo 'Starting job reaper' | trap 'int=1 hot=1' HUP | trap 'int=1 hot=' INT | trap 'echo "Stopping job reaper"; exit 0' TERM | trap '' EXIT | | while [ 1 ]; do | int= | sleep ${JOBWAIT} & | wait | if [ -z "${int}" ] && [ -n "${hot}" ]; then | i=0 l= | while [ ${i} -lt ${MAXJOBS} ]; do | i=`add ${i} 1` | | if [ -f t.${i}.pid ] && read p < t.${i}.pid; then | kill -KILL ${p} | ${rm} -f t.${i}.result | l="${l} ${i}" | fi | done | [ -n "${l}" ] && | printf '%s!! Reaped job(s)%s after %s seconds%s\n' \ | "${COLOR_ERR_ON}" "${l}" ${JOBWAIT} "${COLOR_ERR_OFF}" | fi | done | ) </dev/null & #>/dev/null 2>&1 & | JOBREAPER=$!
Seems to work much, much better even inside a function, and even inside dash if i add the trap trap 'echo "Started job reaper successfully"' USR1 inside, and instead of JOBREAPER=$! i=${!} sleep 1 if kill -USR1 ${i} >/dev/null 2>&1; then JOBREAPER=${i} else printf "%s!! Incapable shell, cannot start zombie child reaper%s\n" \ "${COLOR_ERR_ON}" "${COLOR_ERR_OFF}" fi But understand i do not. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)