Created
May 12, 2020 08:56
-
-
Save JohannesBuchner/85d8c8f1620694df4b09c529437a10af to your computer and use it in GitHub Desktop.
Stop/resume processes when the user is active/inactive in Linux/Xorg
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 | |
# how to identify the processes to STOP/CONT | |
# this is any part of process command line | |
PROCESS="myscript.py" | |
# run this in one terminal: | |
# it tries to resume the processes every so often | |
while sleep 10m; do | |
pgrep -f "${PROCESS}"|xargs -rt kill -CONT | |
done | |
# run this in another terminal: | |
# it stops the processes whenever there is any X event | |
# all the other stuff is for reducing the number of calls | |
xinput test-xi2 --root | | |
grep --line-buffered EVENT | | |
while read i; do date +%s; done | stdbuf -oL uniq | | |
while read j; do pgrep -f "${PROCESS}" |xargs -rt kill -STOP; done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment