[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
'wait' in command group in pipeline fails to recognize child process
From: |
Martin Jambon |
Subject: |
'wait' in command group in pipeline fails to recognize child process |
Date: |
Tue, 22 Jun 2021 02:42:40 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 |
Hello!
I ran into something that looks like a bug to me, although I'm not super
familiar curly-brace command groups.
Bash version: latest from GitHub mirror (commit ce23728: Bash-5.1 patch 7)
Minimal repro:
$ sleep 1 & { wait $!; } | cat
[1] 665454
bash: wait: pid 665454 is not a child of this shell
I was expecting a success, just like we get without the pipeline:
$ sleep 1 & { wait $!; }
[1] 665591
[1]+ Done sleep 1
The following scripts are similar but print PIDs along the way:
---- failing script ----
$ cat wait-for-child
echo "main pid: $$"
/usr/bin/sleep 1 &
job_pid=$!
echo "job pid: $job_pid"
{
echo "command group pid: $$"
wait "$job_pid" || echo "wait failed!"
} | cat
Output:
$ ./bash wait-for-child
main pid: 664755
job pid: 664756
wait-for-child: line 7: wait: pid 664756 is not a child of this shell
command group pid: 664755
wait failed!
^ We see that the current PID in the command group is the same as in the
rest of the shell, as it should be. It is unclear to me why 'wait'
believes that the background job's PID is not of a child.
---- successful script ----
Compare to the same script without having the command group in a
pipeline (I removed '| cat'):
$ cat wait-for-child-ok
echo "main pid: $$"
/usr/bin/sleep 1 &
job_pid=$!
echo "job pid: $job_pid"
{
echo "command group pid: $$"
wait "$job_pid" || echo "wait failed!"
}
$ ./bash wait-for-child-ok
main pid: 664705
job pid: 664706
command group pid: 664705
^ OK
Martin
- 'wait' in command group in pipeline fails to recognize child process,
Martin Jambon <=
- Re: 'wait' in command group in pipeline fails to recognize child process, Greg Wooledge, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Martin Jambon, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Greg Wooledge, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Martin Jambon, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Lawrence Velázquez, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Martin Jambon, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Lawrence Velázquez, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Martin Jambon, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Greg Wooledge, 2021/06/22
- Re: 'wait' in command group in pipeline fails to recognize child process, Chet Ramey, 2021/06/23