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.

Revisions

  1. AmyOlex created this gist Oct 16, 2017.
    29 changes: 29 additions & 0 deletions maxjobs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/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
    }