Question
Do you know any tool/script to send SIGSTOP
(to pause a process) or SIGCONT
(to resume it) to a process by clicking on a graphical window generated by the process?
Some context
There is already a tool called xkill
which kills programs by clicking on a window, but it has no options to send a particular signal. This is a pity, because somewhat related command-line tools like kill
have this option.
Usually I do this via command line by manually obtaining the corresponding process names and using tools like kill
, pkill
or killall
but it would be nice to be able to do this graphically, in a way similar to clicking on a window with the xkill
tool.
Applications
I would find such a tool very useful to graphically pause some heavy processes when the CPU is too "stressed" without terminating them and without losing data which cannot be saved (e.g. for partial results of long calculations).
You can use
xdotool
to allow the user to click a window and obtain its process ID. Then you can usekill
to send e.g. the STOP or CONT signals to that process and freeze/thaw it that way.First, you probably have to install
xdotool
, as it doesn't come preinstalled:Then, the command to get the PID of the process owning a specific window, which can be selected by clicking with the mouse, would be:
This prints the numeric process ID. You can use supply it as argument to
kill -STOP
orkill -CONT
to pause and continue said process. This can be simplified by storing the PID in a variable, like in this little script below, which pauses the clicked window's process for 5 seconds:You could now save this script on your computer and e.g. bind it to a keyboard shortcut.
Improving Byte Commander♦'s answer:
There is xdtool based script for that: https://github.com/RegisterFault/clickstop
The advantage is it will suspend the whole process tree, which is needed for example to suspend multiprocess chrome or firefox.