Skip to content

Instantly share code, notes, and snippets.

@froop
Created May 9, 2011 15:15
Show Gist options
  • Select an option

  • Save froop/962710 to your computer and use it in GitHub Desktop.

Select an option

Save froop/962710 to your computer and use it in GitHub Desktop.
[bsh] 複数コマンド並行実行
#!/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