0
I would like to ask about creating new processes in bash script.
I have script which will execute external programs tests and then check its output status and print if test was successful or not. These test will execute sequentially.
And now I need a few other tests which script create new process for each of these tests max processes of how many tests there are lets say for now I want to run 3 tests in parallel and even with first sequentially tests executions. And I would like to know if there is any how possible to get output status of these separate proceses to my script back and log them? I need to get these value separately of each running process And I do not want to stop these sequentially running processes. And these 3 tests will be running still in cycles with sequentially tests.
So to summarize I need in bash somehow create regression script which will run in cycles TESTS1 whill will be executed sequentially and TESTS2 which will be running in background because their execution si longer then TESTS1. But I need somehow to run TESTS2 in backround, check if are still running get their output status back to parent script to log values and in parallel still executing TESTS1.
Now I am using associative array to log PID of child processes of TESTS2 and testing if particular test id running and if not I start it again. But I do not not How to get its ID. because read of last process output status does not need to be of this test which I am testing is exists.
# Create array
declare -A processes
for test in ${TESTS2[@]};
do
processes[$test]=0
done
# background prcess
fork()
{
OUT=$($TEST)
STATUS=$?
if [ $STATUS -eq 0 ]; then
# do staff if ok
((OK++))
else
# do staff if fail
((FAIL++))
fi
}
# -----------------------------------------------------------------------------
# Repeat Tests i-times
for ((i=1; i<=100; i++))
do
# RUN backgroung proceses
for TEST in ${TESTS2[@]}; do
# check if PID lives
kill -0 ${processes[$TEST]} &> /dev/null
stat=$?
# if 0 or not running run it...
if [[ ${processes[$TEST]} == 0 || $stat > 0 ]]; then
fork $TEST $cnt &
processes[$TEST]=$! # log PID
fi
done
# Cycle through TESTS1
for TEST in ${TESTS1[@]}; do
OUT=$($TEST)
STATUS=$?
if [ $STATUS -eq 0 ]; then
# do staff if ok
((OK++))
else
# do staff if fail
((FAIL++))
fi
echo -ne "** NOTE: Running Regress Tests: Cycle: $i PASS: $ccount FAIL: $fcount ...\r"
done
Can anyone has any ideas? Thanks
Yes Thank you, But wait will stop my parent script and waiting for particular bg process, And I need executing other tests so far and do not wait for bg processes. I need get output status when bg process ends and to not wait for it to end. – TomyOne – 2014-11-19T10:00:18.650