Skip to content

Instantly share code, notes, and snippets.

@masahiro-yoshitachi
Created November 30, 2016 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masahiro-yoshitachi/a3412d119996e6ce94ff767784db4bca to your computer and use it in GitHub Desktop.
Save masahiro-yoshitachi/a3412d119996e6ce94ff767784db4bca to your computer and use it in GitHub Desktop.
マルチスレッド風の処理(Bash)
### マルチスレッドで処理
COMMAND_FILE=${SCRIPT_LOG}/`date '+%Y%m'`/`date '+%Y%m%d'`_$$_command_list.txt
n=8
i=0
while read line
do
# --- バックグラウンドで実行
eval ${line} &
# 直前のPIDを取得
pid[${i}]=$!
# --- 8以上になったら0を設定
i=`expr $i \+ 1`;
if [ ${n} -eq ${i} ];then
wait;
i=0;
fi
done < ${COMMAND_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment