Elaborating on Ingo's hints: Something like this could be used to not to
have
to maintain the state somewhere on disk:
===========
#!/usr/bin/env bash
process_name=$1
for pid in $(pgrep --exact $process_name); do
# Assumes there is no space in the command name
if awk '$3=="T"{exit 1}' /proc/$pid/stat 2>/dev/null
then kill -SIGCONT $pid
else kill -SIGKILL $pid
fi
done
===========
Kind regards,
Joep
Ingo Bürk schreef op 2015-11-08 10:30:
Hi,
one possible solution: save the following as /some/path/stopcont.sh and
bind
bindsym $mod+p exec --no-startup-id /some/path/stopcont.sh
<processname>
Script:
===========
#!/usr/bin/env bash
PROCESS=${1}
FILE="/tmp/${PROCESS}.signal"
if [[ -f "${FILE}" ]]; then
rm ${FILE}
pkill -SIGCONT ${PROCESS}
else
touch ${FILE}
pkill -SIGSTOP ${PROCESS}
fi
===========
This will, of course, assume that the process isn't paused by anything
else as that would make it go out of sync. A better and more robust way
would be to write the script such that it instead uses the information
of /proc/<pid>/stat to check whether the process is currently paused.
If
you use a higher-level language such as Python, you can do this nicely
instead of manually parsing the output. See [1] for some more
information.
[1]
http://stackoverflow.com/questions/6021771/is-there-a-way-to-determine-if-a-linux-pid-is-paused-or-not
Ingo
On 11/08/2015 04:16 AM, Zenny wrote:
Hi,
I am trying to use a keybinding to pause a process temporily,
bindsym $mod+p exec pkill -SIGSTOP <processname>
But I could not figure out how to make pressing to same keybinding to
restart the process?
Currenlty I am using,
bindsym $mod+c exec pkill -SIGCONT <processname>
Instead, I want something like re-pressing $mod+p executes pkill
-SIGCONT <processname>.
Thanks!
/z