Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample of parallel processing in Zsh script.
#!/usr/bin/zsh
worker() {
worker_num=$1
while true
do
exec 9>| lock
flock -x 9
num=$(read -e)
exec 9>&-
if [[ -n $num ]]
then
print "Worker $worker_num : Hello, count=${num}"
else
print "Worker $worker_num ended."
break
fi
done
}
print -l {1..1000} | (
( worker 1 ) &
( worker 2 ) &
( worker 3 ) &
wait
rm lock
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment