Hi Vitaly,
On 31/03/2020 20:07, Vitaly Zuevsky wrote:
I must have confused two concepts: waited process in OS -vs- waited job inside
shell interpreter. I am trying to see how it work in practice:
# true & false &
#
[2] + Done(1) false
[1] + Done true
# wait 2
# echo $?
127
As we preserve job exit codes, I would expect wait command to read them and
free associated jobtab slots. In above example I expect to see 1 in place of
127. What do I miss here?
There are two problems here. The first is that waiting for jobs involves
the % symbol. wait 2 always means "wait for process 2", never "wait for
job 2". To wait for job 2, the syntax is "wait %2". The second problem
is that as soon as you see that "[2] + Done(1)", the job has been
removed the job table already, so "wait %2" no longer works after that.
The blank line (except for the #) indicates that you pressed Return at
that point. In interactive shells, jobs are checked for completion and
removed from the job table automatically when prompting for input. Since
it was practically impossible to press Return before the "true" and
"false" commands had finished, when the next prompt would have been
shown, the jobs were cleaned up. If you had typed "wait %2" before
pressing Return, it would have worked and the subsequent "echo $?" would
have printed "1".
Many thanks for your help.
Best,
Vitaly