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

Re: wait()ing for a job



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