Este seria el código:
launchQuery "$q" &
pid="$(ps -p $! | grep bash)"
ps -p $pid -l | tail -n1 >> log.temp
control=0
while [ $control -eq 0 ]
do
if [ -z "$pid" ]
then
wait $pid
control=1
else
ps -p $pid -l | tail -n1 >> log.temp
sleep 5
fi
pid="$(ps -p $! | grep bash)"
done
launchQuery "$q" &
pid="$(ps -p $! | grep bash)"
ps -p $pid -l | tail -n1 >> log.temp
control=0
while [ $control -eq 0 ]
do
if [ -z "$pid" ]
then
wait $pid
control=1
else
ps -p $pid -l | tail -n1 >> log.temp
sleep 5
fi
pid="$(ps -p $! | grep bash)"
done