[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Why is backgrounded work not considered a 'job' if launc
Re: [Help-bash] Why is backgrounded work not considered a 'job' if launched inside of something being piped to?
Thu, 27 Dec 2018 13:07:32 -0500
On Thu, Dec 27, 2018 at 10:30:45PM +1100, Hales wrote:
> echo -e 'one\ntwo\nthree' | while read line
> example_worker $line &
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 ...
done < <(some process that is not echo)