Skip to content

Instantly share code, notes, and snippets.

@AmyOlex
Created October 16, 2017 15:41
Show Gist options
  • Select an option

  • Save AmyOlex/9c45a29a19cba0f481e6af40def1e0db to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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