test.sh
## the parallel処理のサンプル
for ((i=0;i<5;i++));do
{
sleep 3;echo 1>>aa && echo "done!"
}& #& loop並行実施する様に
done
wait #すべての並行実行完了まで待ちます
実行結果と時間を計る(3秒かかる)
~ koukou.chou.ts$ time ./test.sh
done!
done!
done!
done!
done!
real 0m3.014s
user 0m0.007s
sys 0m0.012s
90201667n:~ koukou.chou.ts$
スクリプトパラレルで実行している様子も見れる
~ koukou.chou.ts$ ps -ef | grep test.sh| grep -v grep
1903612162 98968 95673 0 2:54PM ttys002 0:00.00 /bin/bash ./test.sh
1903612162 98969 98968 0 2:54PM ttys002 0:00.00 /bin/bash ./test.sh
1903612162 98970 98968 0 2:54PM ttys002 0:00.00 /bin/bash ./test.sh
1903612162 98971 98968 0 2:54PM ttys002 0:00.00 /bin/bash ./test.sh
1903612162 98972 98968 0 2:54PM ttys002 0:00.00 /bin/bash ./test.sh
1903612162 98975 98968 0 2:54PM ttys002 0:00.00 /bin/bash ./test.sh