Created
October 16, 2017 15:41
-
-
Save AmyOlex/9c45a29a19cba0f481e6af40def1e0db to your computer and use it in GitHub Desktop.
Controls the flow of a bash for loop so that only so many processes are executed at a time.
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 | |
| ### Author ### | |
| # Amy Olex | |
| # 3/12/15 | |
| # Function: maxjobs | |
| # | |
| ### Description ### | |
| # Essentially a helper function to control how many jobs get started at the same time. | |
| # You will need to source this function in any script you wish to use it in. | |
| # | |
| ### Usage ### | |
| # >> source maxjobs | |
| # >> maxjobs <num jobs> | |
| ####################### | |
| function maxjobs { | |
| if [ $# -ne 1 ] | |
| then | |
| num=1 | |
| else | |
| num=$1 | |
| fi | |
| while [ `jobs -r | wc -l` -ge $num ] | |
| do | |
| sleep 2 | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment