Usually when running application in graphical environment, when I want to close it I click X
in the top left corner of the window or go to File > Close
.
I would like to sometimes close these programs remotely over ssh from terminal using command line, now I use kill
command but I wonder it it does the same as exiting the application properly from itself.
From man kill
default signal appears to be 15) SIGTERM, is this signal going to tell the application I am trying to close to clean up, close open files, save stuff?
Is there a better way if I want to do it from terminal?
The typical way to close application gracefully is to use
kill -TERM 1234
, where1234
is the PID of the window. Problem, however, is that graphical applications are designed to listen for a specific signal from X server itself , not listening for theTERM
signal.That means you would need some kind of agent in between you and the X server to communicate that you want to send appropriate signal. You can of course write a C program, however there aready exists
wmctrl
program ( not-surprisingly written in C ) that does exactly that.Usage of
wmctrl
is simple:It's not installed by default, so get it with
sudo apt-get install wmctrl
There's many uses for
wmctrl
is far beyond just closing windows, so please see more of my answers and Jacob Vlijm's for examples of scripts where it's been usedI think it's worth adding that
wmctrl -xl
will output results like this:Where the
x
requests the window class to be in the output. This is often the easiest way to close the same program every time. Then, we can just supply the window class when closing it:This example will close speedcrunch.