Created
July 11, 2014 02:09
-
-
Save naoh16/84d60c6251f7a33fa5f5 to your computer and use it in GitHub Desktop.
最大実行数を制限してコマンドを実行するサンプル
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/bash | |
# | |
# Sample of job queing | |
# | |
# Copyright (C) 2014 Sunao HARA ([email protected]) | |
# Copyright (C) 2014 Abe laboratory, Okayama university | |
# Last Modified: 2014/07/11 11:08:14. | |
# | |
function queue_job() { | |
MAX_JOB=$1; shift | |
JOBCMD=$@ | |
while [ `jobs | wc -l` -ge 2 ]; | |
do | |
# echo "Waiting: $JOBCMD" | |
sleep 1 | |
done | |
echo Run: $JOBCMD | |
eval $JOBCMD & | |
} | |
queue_job 2 'sleep 5 && echo 1' | |
queue_job 2 'sleep 5 && echo 2' | |
queue_job 2 'sleep 5 && echo 3' | |
queue_job 2 'sleep 5 && echo 4' | |
queue_job 2 'sleep 5 && echo 5' | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment