Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created January 8, 2014 15:35
Show Gist options
  • Save coderofsalvation/8318643 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8318643 to your computer and use it in GitHub Desktop.
limitprocess is a bashfunction which starts bash cmds but limits to maximum of N running instances (handy for cronjobs)
# Starts bash cmds but limits to maximum of N running instances (handy for cronjobs)
# usage: ./limitprocess <max parallel processes> ..yourcommands..
# @dependancies: ps grep wc
# @param int maximum number of parallel processes
function limitprocess(){
MAXINSTANCES="$1"; shift;
processes=$(ps aux | grep "$*" | grep -v grep | wc -l )
((processes < MAXINSTANCES)) && "$@" || echo "already $MAXINSTANCES processes running"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment