Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 08 Nov 2006 11:07:06 +0100
From:      nicky <nicky@valuecare.nl>
To:        freebsd-questions@freebsd.org
Subject:   Parallel shell scripts.
Message-ID:  <4551AC4A.2000108@valuecare.nl>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4551AC4A.2000108>