Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: wait()ing for a job
- X-seq: zsh-users 18926
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: wait()ing for a job
- Date: Sat, 05 Jul 2014 10:32:33 -0700
- In-reply-to: <20140705050758.GA3836@solfire>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20140705050758.GA3836@solfire>
On Jul 5, 7:07am, meino.cramer@xxxxxx wrote:
}
} I want to write a zsh-script to start several rsync-jobs in background
} and 'wait' for each of them to end. I need the return code of each
} of them.
[...]
} I need all return codes -- if one rsync fails, I got a problem.
}
} What is it, what I don't correctly understand from the manpage -- what
} does wait according to the return codes of several jobs?
Unfortunately you can't accomplish what you need with only "&" and "wait".
The wait builtin always returns the status for exactly one job, either
the first one among those you specified as the arguments, or the last one
out of all possible jobs. If several jobs exit "too close together" then
the return status from some of them may be lost, because the shell will
handle them asynchronously while "wait" is not active. See e.g. comments
in Functions/Misc/zargs relating to the --max-procs option.
One way to achieve what you want is to wrap each rsync job in a subshell
which finishes with "print $?". This will cause the subshell to block
until something reads its output, so that you can be sure of associating
the correct exit status with each rsync. If you combine this with the
"... {var}>&1" syntax, you can dynamically assign descriptor numbers to
each subshell and either monitor them with "zselect" or poll them with
"read -t 0 <&$var". I don't have time right now to write up an example
of this but I may be able to do so later if you can't work it out.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author