It probably never makes sense to background the "wait" builtin, but
if one makes this error, the
resulting error message is nonsensical and confusing:
wait: pid nnnnn is not a child of this shell ## (where nnnnn is the pid)
Repeat-By:
E.g.:
#!/bin/bash
stdinFile=/tmp/stdin.$$
echo "echo \"here we are!\" ; sleep 3 ;" > $stdinFile
bashCommand=`cat $stdinFile`
/bin/bash -s <$stdinFile & ## it doesn't matter which
# /bin/bash -c "$bashCommand" & ## of these two lines is uncommented
pidOfBackgroundProcess=$! ;
echo "pidOfBackgroundProcess=$pidOfBackgroundProcess" ;
wait $pidOfBackgroundProcess & ## the ampersand here is the error that
triggers the nonsensical error message
The typescript of an actual run of the above script looked like this:
root@zorba:/home/srn# /tmp/z.sh
here we are!
pidOfBackgroundProcess=20944
/tmp/z.sh: line 10: wait: pid 20944 is not a child of this shell
(But, of course, pid 20944 *was* in fact a child of this shell.)
Fix:
Never background an invocation of the wait builtin, accidentally
or otherwise.
(Unfortunately, I'm not always alert enough to avoid doing this,
and I suspect there
are others like me.)
Steve Newcomb
srn@coolheads.com
+1 910 363 4032