I need to simulate the behavior of the keyboard shortcut (ALT+F4) using Terminal for a given application.
If I open for example gedit and click ALT + F4 , then GEDIT will be xkilled. If I want to achieve same thing using Terminal, how should I proceed?
The following command (in order to kill gedit process) works fine:
kill $eval `pidof gedit`
yet, the command
xkill -id gedit
prompts me to click on the application client window in order to xkill it, thing That I want to avoid from the beginning.
The reason why I want to achieve this behavior is that some applications clients keep their process running, even though you ALT+F4 it. My need is that I have an application that starts up on every login and I need to automatically close its client 3 or 5 seconds after it shows up.
An equivalent of
xkill
is thewindowkill
function inxdotool
. If you don't havexdotool
installed, please runWith this tool you can indeed kill a window by using the search option and by specifying its class:
You can find the pid of the process with
getwindowpid
, but just specifying the name of the class of window (i.e--class gedit
) is enough. The tool is non-interactive in the sense that you do not need to click on a window to kill it as you sometimes need to do withxkill
.More information on the options available with
xdotool
are available withman xdotool
and at the Ubuntu manpages online. The manpages explain well howxdotool
can be incorporated into a script much easier thanxkill
could be.So I think probably
xdotool's
windowkill option is what you want and it may be more handy than that ofxkill
.However, if you still want to use
xkill
and feed it the window's resource id, so that it closes the window without prompting you, you could parse the output ofxwininfo
, as in this example using the programMeld
:However, the name of the program sent to
xwininfo
must be in the proper case, so launch the program beforehand, and, in our example here, see if it isMeld
ormeld
.I prefer the
xdotool
command I gave above, as the case doesn't have to be correct:Meld
ormeld
will work as thesearch --name
switch instead uses regex to match a given string and ignores the case.you can use
killall
which will send a TERMSIG (terminate signal) to the application you specify. you can use killall with the following commandfor example, you can close firefox with
if for some reason you must find the correct id of an application/process, you can always use
ps
to see all running processes and their names.will definitely kill everything associated with that pid.
to find the pid, I use
they can then be incorporated into one command if you need to do it often
Use
top
Command to get particular process Id. Note down it and type following command to kill Process.