Skip to content

Instantly share code, notes, and snippets.

@jason51285128
Created June 18, 2019 08:40
Show Gist options
  • Save jason51285128/0f33d4babd0fd20f3e1d8ab6d5c8244c to your computer and use it in GitHub Desktop.
Save jason51285128/0f33d4babd0fd20f3e1d8ab6d5c8244c to your computer and use it in GitHub Desktop.
multi process program in bash
#!/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