Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
Your question is not clear do you mean to kill a process using terminal ? –  Ramzi Njeim Nov 11 '12 at 16:57
1  
Not really. I want to achieve the same behavior as ALT+F4 –  Hanynowsky Nov 11 '12 at 17:39
3  
Xkill (or Alt+F4) will only terminate the connection of an application to the XServer. This may also kill the application but depending on the application it may also not. We should therefore not rely on xkill when we want to make sure an appliciation is terminated. –  Takkat Nov 11 '12 at 20:58
    
That's exactly what I want. I just want to separate the app from X server. –  Hanynowsky Nov 12 '12 at 21:41

4 Answers 4

up vote 2 down vote accepted

An equivalent of xkill is the windowkill function in xdotool. If you don't have xdotool installed, please run

sudo apt-get install xdotool

With this tool you can indeed kill a window by using the search option and by specifying its class:

xdotool search --class gedit windowkill

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 with xkill.

More information on the options available with xdotool are available with man xdotool and at the Ubuntu manpages online. The manpages explain well how xdotool can be incorporated into a script much easier than xkill could be.

So I think probably xdotool's windowkill option is what you want and it may be more handy than that of xkill.

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 of xwininfo, as in this example using the program Meld:

xkill -id $(xwininfo -name Meld | awk -F ':*"*' '{print $3}')

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 is Meld or meld.

I prefer the xdotool command I gave above, as the case doesn't have to be correct: Meld or meld will work as the search --name switch instead uses regex to match a given string and ignores the case.

share|improve this answer
    
Thanks for this fine asnwer. That's exatcly what I wanted. I did not know xdotool existed and I do prefer it too :) However the xkill command you gave is going to be very handy. –  Hanynowsky Nov 12 '12 at 21:48

Use top Command to get particular process Id. Note down it and type following command to kill Process.

kill <process id>
share|improve this answer
    
Thanks for the response. Well, I know how to spot a process and kill it. That's not a problem. In my question I specified that I need to separate the running app from X Server using xkill command. –  Hanynowsky Nov 12 '12 at 21:43
kill -9 <id>

will definitely kill everything associated with that pid.

to find the pid, I use

ps -u $USER -f | grep gedit

they can then be incorporated into one command if you need to do it often

share|improve this answer

you can use killall which will send a TERMSIG (terminate signal) to the application you specify. you can use killall with the following command

killall <id> 

for example, you can close firefox with

kilall firefox

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.

share|improve this answer
    
Thanks for the answer, yet, that's not what I am looking for. Killall will kill all processes related to a resource application. Sure; i can grep a resource pid using: ps -A | grep gedit –  Hanynowsky Nov 11 '12 at 18:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.