Skip to content

Instantly share code, notes, and snippets.

@reasonset
Created June 5, 2016 13:48
Show Gist options
  • Save reasonset/782725e1648aca2d60fa96590433f2f4 to your computer and use it in GitHub Desktop.
Save reasonset/782725e1648aca2d60fa96590433f2f4 to your computer and use it in GitHub Desktop.
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