Created
May 1, 2017 13:34
-
-
Save ceremcem/864dd94b52ffe7b18da29558df4f1f5b to your computer and use it in GitHub Desktop.
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 | |
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