#!/bin/bash
# Usage:
# slowcmd.sh tar cf ~/backup.tar /usr/src/linux-2.6.25
"$@" &
PID=$!
echo "PID is $PID"
TOGGLE='Resume'
RUN_SECONDS=2
PAUSE_SECONDS=10
function procnumber () {
echo `ps ax | awk -v var=$1 '{if($1==var){printf("%d", $1)}}'`
}
while [ "$PID" != "" ]; do
if [ "$TOGGLE" = "Pause" ]; then
echo "Stopping PID $PID"
kill -s STOP $PID
sleep "$PAUSE_SECONDS"
TOGGLE='Resume'
else
echo "Resuming PID $PID"
kill -s CONT $PID
sleep "$RUN_SECONDS"
PID=$(procnumber $PID)
TOGGLE='Pause'
fi
done