Created
June 5, 2016 13:48
-
-
Save reasonset/782725e1648aca2d60fa96590433f2f4 to your computer and use it in GitHub Desktop.
Sample of parallel processing in Zsh script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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