|
In bash, we (&) multi-threaded through the background.
for ((i = 1; i <= pairs; i ++))
do
mongo = "mongo_00 $ i"
acmeair_web = "acmeair_web_00 $ i"
{
docker run --name $ mongo -d -p $ port_m: 27017 mymongodb
docker run -d -p $ port: 9080 --name $ acmeair_web --link $ {mongo}: mongo acmeair / web
} &
((Port ++))
((Port_m ++))
done
wait
We have added a {&} {} so that you can execute in the background, the above is equivalent to two pairs simultaneously performed, wait wait after they are executed.
-------------------------------------------------- ------------------------------
We are all of the above, the number of concurrent uncontrollable, following controllable.
tmp_fifofile = "/ tmp / $$. fifo"
mkfifo $ tmp_fifofile # Create a fifo file types
exec 6 < > $ tmp_fifofile # fifo will fd6 point type
rm $ tmp_fifofile
thread = 15 # the number of threads defined herein
for ((i = 0; i <$ thread; i ++)); do
echo
done> & 6 # fd6 in fact, it is placed in a carriage return $ thread
for ((i = 0; i <50; i ++)); do # 50 cycles
read -u6 # a read -u6 command execution time is subtracted from fd6 a carriage return, and then execute down
# Fd6 no carriage return when stopped here, the number of threads in order to achieve control
{
{
docker run ... mongodb
docker run ... acmeair / web
} && {
echo "subprocess is finished"
} || {
echo "error"
}
echo> & # 6 after the end of the process when, again in fd6 add a carriage return, which make up that read -u6 minus
} &
done
wait # wait for all background child process ends
exec 6> & - # Close fd6
exit 01 |
|
|
|