Parallel shell scripts.

nicky nicky at valuecare.nl
Wed Nov 8 10:07:14 UTC 2006


Hello,

This might be a bit off topic, but can't find anything really useful 
when searching the internet. So i hope someone can point me in the right 
direction

I have to start 2 processes in the background (running in parallel), 
capture their return codes and after all 4 have completed successfully i 
want to continue with the main script.

Sofar i have this (below), however is this the proper way to do it?

#!/bin/sh -

PIDLIST=""

./childprocessA.sh &
PIDLIST="$PIDLIST $!"

./childprocessB.sh &
PIDLIST="$PIDLIST $!"

for PID in $PIDLIST; do
        wait $PID
        rc=$?
        echo "Job $PID exited with status $rc"
        if [ $rc -ne 0 ]; then
          exit $rc
        fi
done

**** the rest of the main script ****


Regards,
Nick


More information about the freebsd-questions mailing list