Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15615 > unrolled thread
| Started by | Luiz Angelo Daros de Luca <luizluca@gmail.com> |
|---|---|
| First post | 2019-11-19 16:51 -0300 |
| Last post | 2019-11-19 16:51 -0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
bash loses control of jobs inside a command substitution Luiz Angelo Daros de Luca <luizluca@gmail.com> - 2019-11-19 16:51 -0300
| From | Luiz Angelo Daros de Luca <luizluca@gmail.com> |
|---|---|
| Date | 2019-11-19 16:51 -0300 |
| Subject | bash loses control of jobs inside a command substitution |
| Message-ID | <mailman.2019.1574193089.13325.bug-bash@gnu.org> |
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 top | Article view | gnu.bash.bug
csiph-web