You can create a FIFO and read that while the background process is running. For each line you read, you can do whatever you want with the child_pid.
First we need a small sample program:
bgp() { sleep 1; echo 1; sleep 1; echo 2; sleep 1; echo 3; }
Then create a fifo (maybe choose some path in /tmp)
tmp_fifo="/tmp/my_fifo"
rm "${tmp_fifo}" &>/dev/null
mkfifo "${tmp_fifo}"
Start your process in the background and redirect the output to the FIFO:
bgp > "${tmp_fifo}" &
child_pid=$!
Now read the output until the child process dies.
while true; do
if jobs %% >&/dev/null; then
if read -r -u 9 line; then
# Do whatever with $child_pid
echo -n "output from [$child_pid]: "
echo $line
fi
else
echo "info: child finished or died"
break
fi
done 9< "${tmp_fifo}"