2

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).

2 Answers2

2

You can use xdotool to allow the user to click a window and obtain its process ID. Then you can use kill 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:

sudo apt install xdotool

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:

xdotool selectwindow getwindowpid

This prints the numeric process ID. You can use supply it as argument to kill -STOP or kill -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:

#!/bin/bash
wpid="$(xdotool selectwindow getwindowpid)"
kill -STOP "$wpid"
sleep 5
kill -CONT "$wpid"

You could now save this script on your computer and e.g. bind it to a keyboard shortcut.

Note: man xdotool says about the getwindowpid subcommand:

"This requires effort from the application owning a window and may not work for all windows."

In other words, it might not work at all or at least not exactly as intended with some applications.
It could also happen that multiple windows have the same corresponding process ID, like e.g. all gnome-terminal instances are owned by the same parent. In that case, the command would freeze all of them, which might not be intended.

Byte Commander
  • 110,243
1

Improving Byte Commander♦'s answer:

There is xdtool based script for that: https://github.com/RegisterFault/clickstop

Bash script that uses xdotool to send SIGSTOP and SIGCONT signals to the process tree of an application that was clicked on

The advantage is it will suspend the whole process tree, which is needed for example to suspend multiprocess chrome or firefox.

kotofos
  • 11