Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#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.