Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15615
| From | Luiz Angelo Daros de Luca <luizluca@gmail.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | bash loses control of jobs inside a command substitution |
| Date | 2019-11-19 16:51 -0300 |
| Message-ID | <mailman.2019.1574193089.13325.bug-bash@gnu.org> (permalink) |
| References | <CAJq09z4OWeZchYVH9U1G2OuTzdXBh+F8gLEjkqcJemohzi8dDg@mail.gmail.com> |
Hello,
Normally 'wait -n' will return the exit code of background process when
they terminate before wait is runned. However, when bg processes and 'wait
-n' runs inside a command substitution, bash loses control of bg process as
soon as they exit.
nr=${1:-5}
subjobs() {
local -a pids
for a in $(seq $nr); do
(
sleep 0.$a
exit $a
) &
pids+=($!)
done
sleep $1
for a in $(seq $nr); do
wait -n
echo Got one child $? >&2
done
}
# run wait -n before jobs have fininshed
echo Command substs no sleep
a=$(subjobs 0 )
echo Command substs pipe no sleep
b=$(subjobs 0 | cat)
echo direct no sleep
subjobs 0
# run wait -n after jobs have fininshed
echo Command substs sleep
a=$(subjobs 1)
echo Command substs pipe sleep
b=$(subjobs 1 | cat)
echo direct sleep
subjobs 1
Output:
Command substs no sleep
Got one child 1
Got one child 2
Got one child 3
Got one child 4
Got one child 5
Command substs pipe no sleep
Got one child 1
Got one child 2
Got one child 3
Got one child 4
Got one child 5
direct no sleep
Got one child 1
Got one child 2
Got one child 3
Got one child 4
Got one child 5
Command substs sleep
Got one child 5
Got one child 127
Got one child 127
Got one child 127
Got one child 127
Command substs pipe sleep
Got one child 127
Got one child 127
Got one child 127
Got one child 127
Got one child 127
direct sleep
Got one child 1
Got one child 2
Got one child 3
Got one child 4
Got one child 5
And two related features requests: 1) It seems that pids args are ignored
by wait when '-n' is specified. However, it would be a nice add_on to use
the list of pids as a filter. 2) 'wait -n' lacks a way to get dead child
PID, requiring some race conditions techniques to get it.
Regards,
--
Luiz Angelo Daros de Luca
luizluca@gmail.com
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
bash loses control of jobs inside a command substitution Luiz Angelo Daros de Luca <luizluca@gmail.com> - 2019-11-19 16:51 -0300
csiph-web