Skip to content

Instantly share code, notes, and snippets.

@ceremcem
Created May 1, 2017 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceremcem/864dd94b52ffe7b18da29558df4f1f5b to your computer and use it in GitHub Desktop.
Save ceremcem/864dd94b52ffe7b18da29558df4f1f5b to your computer and use it in GitHub Desktop.
#!/bin/bash
screen -wipe
screen -mdS mytest bash -c 'for i in {1..10}; do echo "this is $i" > myfile; sleep 1; done'
PID=$(screen -list | grep mytest | cut -f1 -d'.' | sed 's/\W//g')
echo "PID is: $PID"
pause () {
echo "pausing process $PID"
kill -STOP $PID
}
resume () {
echo "resuming process $PID"
kill -CONT $PID
}
is_alive () {
if [[ "$(ps -o pid= -p $PID)" == "$PID" ]]; then
return 0
else
return 1
fi
}
on_exit () {
kill -9 $PID
}
trap on_exit INT
while is_alive; do
echo "$PID is still alive..."
sleep 0.1
pause
read -p "Press [Enter] key to continue..."
resume
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment