Skip to content

Instantly share code, notes, and snippets.

@tokland
Created September 18, 2015 12:12
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 tokland/0046f0e7c225fdfdefad to your computer and use it in GitHub Desktop.
Save tokland/0046f0e7c225fdfdefad to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Toggle the state (STOPPED/RUNNING) of a process, clicking to its window.
set -e
debug() { echo "$@" 2>&1; }
die() { local MESSAGE=$1
debug "Error: $MESSAGE"
exit 1
}
PID=$(xprop _NET_WM_PID | cut -d' ' -f3)
test "$PID" || die "Could not get PID"
debug "PID: $PID"
STATE=$(cat /proc/$PID/status | grep "^State:" | awk '{print $2}')
test "$STATE" || die "Could not get process state"
debug "State: $STATE"
if test "$STATE" = "T"; then # T = stopped
sudo kill -SIGCONT $PID
else
sudo kill -SIGSTOP $PID
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment