I wrote this script for run postgresql pg_dump of multiples schemas. Since it takes much time to finishes all i'd improved it by running simultaneous dumps with this:
for SCHEMA in $SCH
do
while [ $(jobs | wc -l | xargs) -ge $PROC ]; do sleep 5; done
/usr/pgsql-$PGVER/bin/pg_dump -h $PGHOST -p $PORT -U postgres -d $DB -n $SCHEMA -Fc -Z 1 2> $LOGDIR/$SCHEMA'-'$DATA'.log' | $ENCCMD $DUMPDIR/$SCHEMA'-'$DATA.bkp.enc $ENCKEY &
done
wait
So basically what this done is get the number of the jobs running, and if greater or equals 5 it waits until the number of process decreases, keeping at least 5 dumps running simultaneous until finished all schemas.
The problem is: sometimes it get stuck in "while loop", the "jobs | wc -l" always returning number 5, and checking the linux processes there isn't any dump running