Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[BUG?] "wait <PID>" sometimes confused with multiple childs



Hello,

I have a problem with a script starting several subshells in background then checking their return code. It looks like the "wait <PID>" builtin is sometimes returning the error code of another child.

Here is a script reproducing this behavior. Several childs are started in a first loop with predefined return code, their PID saved, then we wait for each of them in a second loop and check their RC:
------start-----
#!/bin/zsh

while true; do
	pids=()
	for task in {1..16} ; do
		( sleep .1 ; exit $task ) &
		pids+=($!)
		# uncomment to prevent bug
		#sleep .1
	done
	for task in {1..16} ; do
		wait $pids[task]
		rc=$?
		if (( rc != task )) ; then
			echo "  FAIL $pids[task]" $rc $task
		fi
	done
	echo "done $pids"
done
------end-----

On my machine, I have many "FAIL ..." printed, around 1 "FAIL" every 2 "done".
If we comment out the "sleep" above, no more fails are printed. I also tried with bash (with a few syntax changes), and it is always working as expected.

Is it a bug or am I missing something?

Antoine



Messages sorted by: Reverse Date, Date, Thread, Author