Created
May 9, 2011 15:15
-
-
Save froop/962710 to your computer and use it in GitHub Desktop.
[bsh] 複数コマンド並行実行
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/sh | |
| TIMES=3 | |
| # 複数コマンドを平行して実行 | |
| idx=0 | |
| while test $idx -lt $TIMES | |
| do | |
| ./hoge.sh $idx & | |
| eval pid$idx=\$! # プロセスID | |
| idx=`expr $idx + 1` | |
| done | |
| # 各コマンドが終了するまで待機 | |
| idx=0 | |
| while test $idx -lt $TIMES | |
| do | |
| eval pid=\$pid$idx | |
| wait $pid | |
| eval rc$idx=\$? | |
| idx=`expr $idx + 1` | |
| done | |
| # 全て成功したか確認 | |
| idx=0 | |
| while test $idx -lt $TIMES | |
| do | |
| eval rc=\$rc$idx | |
| test $rc -eq 0 || exit 1 | |
| idx=`expr $idx + 1` | |
| done | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment