On Thu, Dec 27, 2018 at 10:30:45PM +1100, Hales wrote:
echo -e 'one\ntwo\nthree' | while read line
do
example_worker $line &
done
Because the pipeline creates two subshells. Your background jobs are
executed from within one of these subshells. When that subshell exits,
there goes the parent of the background jobs. With no parent, they are
orphaned, and adopted by init, and your main shell process (their
grandparent) is NOT able to wait for them.
You must rearrange your code so that the background jobs are NOT run
from within a subshell.
For example, this is a common idiom:
while read -r line; do ...
foo &
done < <(some process that is not echo)