bash - Problem with suspending and resuming job -


i have driver script manages job string can run jobs in parallel or sequentially based on dependency graph. example:

job              predecessors                 null b                c                d                b e                d, c f                e 

the driver starts in background , waits complete suspending itselfusing bash built-in suspend. on completion, job sends sigcont driver start b , c in background , suspend again, , on.

the driver has set -m job control enabled.

this works fine when driver started in background. however, when driver invoked in foreground, first call suspend works fine. second call seems turn 'exit' reports "there stopped jobs" , does not exit. third call suspend turns 'exit' , kills driver , children [as should considering second converted call 'exit'].

and question: is expected behavior? if so, why , how work around it?

thanks.

code fragments below:

driver:

            step in $(hash_keys 'running_hash')                                 proc=$(hash_find 'running_hash' $step)                     if [ $proc ]                                                 # added grep ensure process found                             ps -p $proc | grep $proc > /dev/null 2>&1                             if [ $? -eq 0 ]                                                                 log_msg_to_stderr $sev_debug "proc $proc running: suspending execution"                                     suspend                                      # execution resumes here on receipt of sigcont                                     log_msg_to_stderr $sev_debug "signal received: continuing execution"                                     break                             fi                     fi             done 

job:

## $$ driver's pid kill -sigcont $$ 

i have think over-complicating things playing job control , suspend, etc. here example program keeps 5 children running @ times. once second looks see if went away (much more efficiently ps|grep, btw) , starts new child if necessary.

#!/usr/bin/bash  set -o monitor trap "pkill -p $$ -f 'sleep 10\.9' >&/dev/null" sigchld  totaljobs=15 numjobs=5 worktime=10 curjobs=0 declare -a pidlist  dojob() {   slot=$1   time=$(echo "$random * 10 / 32768" | bc -l)   echo starting job $slot args $time   sleep $time &   pidlist[$slot]=`jobs -p %%`   curjobs=$(($curjobs + 1))   totaljobs=$(($totaljobs - 1)) }  # start while [ $curjobs -lt $numjobs -a $totaljobs -gt 0 ]    dojob $curjobs  done  # poll jobs die, restarting while have them while [ $totaljobs -gt 0 ]    ((i=0;$i < $curjobs;i++))        if ! kill -0 ${pidlist[$i]} >&/dev/null            dojob $i       break      fi    done    sleep 10.9 >&/dev/null  done wait 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -