zsh-workers
 help / color / mirror / code / Atom feed
From: "Antoine C." <acalando@free.fr>
To: zsh-workers@zsh.org
Subject: [BUG?] "wait <PID>" sometimes confused with multiple childs
Date: Mon, 12 Mar 2018 14:23:59 +0100 (CET)	[thread overview]
Message-ID: <1328064061.551458859.1520861039419.JavaMail.root@zimbra62-e11.priv.proxad.net> (raw)


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


             reply	other threads:[~2018-03-12 13:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180312133446epcas1p2c0b1934921ed5c33ccf5e9aaaf9f6a9c@epcas1p2.samsung.com>
2018-03-12 13:23 ` Antoine C. [this message]
2018-03-12 14:19   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1328064061.551458859.1520861039419.JavaMail.root@zimbra62-e11.priv.proxad.net \
    --to=acalando@free.fr \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).