help-bash
[Top][All Lists]
Advanced

[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


From: Greg Wooledge
Subject: Re: [Help-bash] Why is backgrounded work not considered a 'job' if launched inside of something being piped to?
Date: Thu, 27 Dec 2018 13:07:32 -0500
User-agent: NeoMutt/20170113 (1.7.2)

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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]