LoginSignup
3
3

More than 5 years have passed since last update.

shellでも並行実行できる

Last updated at Posted at 2014-11-14
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


3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3