bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Async processes started in functions not reliably started


From: Steffen Nurpmeso
Subject: Re: Async processes started in functions not reliably started
Date: Sun, 04 Aug 2019 01:17:15 +0200
User-agent: s-nail v14.9.14-3-g96dc286e

Steffen Nurpmeso wrote in <address@hidden>:
  ...
 |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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]