Created
November 18, 2014 23:24
-
-
Save thomassuckow/db28b6c1224f614ff31a to your computer and use it in GitHub Desktop.
Script to limit the number of running processes to one more than the number of cores. Symlink this script to /usr/local/bin/ named as the binary you want to throttle.
This file contains 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 | |
CMD=$(basename $0) # command used to call this script | |
CMD=$(type -a -p $CMD | sed -n 2p) #find the next highest priority | |
RUNNING=$(grep procs_running /proc/stat|cut -d " " -f 2) | |
BLOCKED=$(grep procs_blocked /proc/stat|cut -d " " -f 2) | |
PROCESSLIMIT=$(grep cpu /proc/stat | wc -l) | |
#Wait for running processes to die down | |
while [ $RUNNING -gt $PROCESSLIMIT ]; do | |
sleep 1 | |
RUNNING=$(grep procs_running /proc/stat|cut -d " " -f 2) | |
BLOCKED=$(grep procs_blocked /proc/stat|cut -d " " -f 2) | |
PROCESSLIMIT=$(grep cpu /proc/stat | wc -l) | |
done | |
exec $CMD $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment