Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stop/resume processes when the user is active/inactive in Linux/Xorg
#!/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
You can’t perform that action at this time.