Created
January 8, 2014 15:35
-
-
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)
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
# 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