Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:148221
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#Pausing all but x CPU-intensive tasks
 
PAUSEQUEUENUM=0
ACTIVEQUEUENUM=0
 
function putinpausequeue {
kill -STOP $1
PAUSEQUEUE="$PAUSEQUEUE $1"
PAUSEQUEUENUM=$(($PAUSEQUEUENUM+1))
echo "Notice. I am pausing $1 . The pause queue is now $PAUSEQUEUE"
}
 
function regenerateactivequeue {
OLDACTIVEQUEUE=$ACTIVEQUEUE
ACTIVEQUEUE=""
ACTIVEQUEUENUM=0
for PID in $OLDACTIVEQUEUE
do
if [ -d /proc/$PID ] ; then
ACTIVEQUEUE="$ACTIVEQUEUE $PID"
ACTIVEQUEUENUM=$(($ACTIVEQUEUENUM+1))
fi
done
}
 
function putinactivequeue {
kill -CONT $1
ACTIVEQUEUE="$ACTIVEQUEUE $1"
ACTIVEQUEUENUM=$(($ACTIVEQUEUENUM+1))
echo "Notice. I am resuming $1"
}
 
function processpausequeue {
while [ $PAUSEQUEUENUM -gt 0 ]; do
echo "Notice. There are $PAUSEQUEUENUM processes paused, and $ACTIVEQUEUENUM processes active . The paused processes are $PAUSEQUEUE , and the active processes are $ACTIVEQUEUE"
regenerateactivequeue
if [ $ACTIVEQUEUENUM -lt 2 ]; then
set -- $PAUSEQUEUE
PIDTOPROCESS=$1
shift
PAUSEQUEUE=$@
PAUSEQUEUENUM=$(($PAUSEQUEUENUM-1))
putinactivequeue $PIDTOPROCESS
else
echo "Notice. No processes activated"
fi
sleep 5
done
while [ $ACTIVEQUEUENUM -gt 0 ]; do
echo "Notice. There are $ACTIVEQUEUENUM processes active . The active processeses are $ACTIVEQUEUE"
regenerateactivequeue
sleep 5
done
echo "Notice. Done now"
}
 
sleep 150 > log1.txt & #Insert really CPU-intensive task here
PID=$! ; sleep 1; putinpausequeue $PID
sleep 150 > log2.txt & #Insert really CPU-intensive task here
PID=$! ; sleep 1; putinpausequeue $PID
sleep 150 > log3.txt & #Insert really CPU-intensive task here
PID=$! ; sleep 1; putinpausequeue $PID
 
processpausequeue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.