Hi,

sorry, my last email didn't go to the mailing list which I diidn't even
notice until this email. Below is my previous email as a quote which
also has a script using /proc/../stat. Never hurts to have multiple
solutions :)
> Hi,
>
> here's a script using /proc/.../stat. The usage is as before. The only
> assumption now is that the process is running exactly once.
>
> ====
> #!/usr/bin/env bash
> PROCESS=${1}
> STATE=$(cat /proc/$(pgrep ${PROCESS})/stat | awk -F' ' '{print $3}')
>
> [[ "${STATE}" = "T" ]] && pkill -SIGCONT ${PROCESS} || pkill -SIGSTOP
> ${PROCESS}
> =====



On 11/08/2015 05:22 PM, Joep van Delft wrote:
> 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

Reply via email to