Path: csiph.com!3.eu.feeder.erje.net!feeder.erje.net!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Steffen Nurpmeso Newsgroups: gnu.bash.bug Subject: Re: Async processes started in functions not reliably started Date: Sun, 04 Aug 2019 01:17:15 +0200 Lines: 63 Approved: bug-bash@gnu.org Message-ID: References: <20190803224008.dVNLU%steffen@sdaoden.eu> <20190803231715.YFelC%steffen@sdaoden.eu> NNTP-Posting-Host: lists.gnu.org X-Trace: usenet.stanford.edu 1564881131 29022 209.51.188.17 (4 Aug 2019 01:12:11 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org In-Reply-To: <20190803224008.dVNLU%steffen@sdaoden.eu> Mail-Followup-To: bug-bash@gnu.org, Steffen Nurpmeso User-Agent: s-nail v14.9.14-3-g96dc286e OpenPGP: id=EE19E1C1F2F7054F8D3954D8308964B51883A0DD; url=https://ftp.sdaoden.eu/steffen.asc; preference=signencrypt BlahBlahBlah: Any stupid boy can crush a beetle. But all the professors in the world can make no bugs. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.144.132.164 X-Mailman-Approved-At: Sat, 03 Aug 2019 21:12:09 -0400 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20190803231715.YFelC%steffen@sdaoden.eu> X-Mailman-Original-References: <20190803224008.dVNLU%steffen@sdaoden.eu> Xref: csiph.com gnu.bash.bug:15293 Steffen Nurpmeso wrote in <20190803224008.dVNLU%steffen@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 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)