Created
June 18, 2019 08:40
-
-
Save jason51285128/0f33d4babd0fd20f3e1d8ab6d5c8244c to your computer and use it in GitHub Desktop.
multi process program in bash
This file contains hidden or 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
#!/bin/bash | |
task() | |
{ | |
echo "task process in $1" | |
sleep 3 | |
echo "0" >& 6 | |
} | |
fifo=/tmp/$.fifo | |
mkfifo $fifo | |
exec 6<>$fifo | |
rm $fifo | |
for i in `seq 0 9`; do | |
{ | |
task $i | |
} & | |
done | |
for i in `seq 0 9`; do | |
read -u 6 result | |
if [ $result -ne 0 ]; then | |
echo "task $i failed!" | |
fi | |
done | |
exec 6>&- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment