How to Kill Linux Processes/Unresponsive Applications Using ‘xkill’ Command

How do we kill a resource/process in Linux? Obviously we find the PID of the resource and then pass the PID to the kill command.

Speaking more accurately, we can find PID of a resource (say terminal) as:

$ ps -A | grep -i terminal

6228 ?        00:00:00 gnome-terminal

In the above output, the number ‘6228‘ is the PID of process (gnome-terminal), use the kill command to kill the process as shown below.

$ kill 6228

The kill command sends a signal to a process, whose PID is passed along with the command.

Alternatively, we can use pkill command, which kills a process based upon name and other attributes of a process. To kill a process say whose name is terminal, we need to execute:

$ pkill terminal

Note: The process name length in pkill is limited to 15 characters.

pkill seems more handy as you can kill a process without have to find out its PID. But if you want to have a better control on your system nothing beats ‘kill‘ command. Using kill you will have better insight of what process you are killing.

We have already covered a detailed guide on kill, pkill and killall commands.

For those who are running X server there is another tool called xkill which can kill a process from its X window without passing process name or its PID.

xkill utility forces X server to close communications to its client which results into killing of client by its X resource. xkill which is a part of X11 utilities is very handy in killing unnecessary windows.

It support options like connect to specific X Server (-display displayname) using display number when multiple X Servers are running on a host simultaneously and kill all the client (-all, not recommended) with top-level windows on the screen as well as take frame (-frame) into account.

To get a list of all the clients you may run:

$ xlsclients
Sample Output
'  ' /usr/lib/libreoffice/program/soffice
deb  gnome-shell
deb  Docky
deb  google-chrome-stable
deb  soffice
deb  gnome-settings-daemon
deb  gnome-terminal-server

If no resource identifier is passed with id, xkill turns the mouse Pointer into special Symbol, similar to ‘X‘. Just click on the window you want to kill and this will kill its communication with server or say the program gets killed.

$ xkill
Xkill Command
Kill Process Using xkill

It is important to notice that xkill do not guarantee that closing its communication will kill/abort it successfully. Most of the application will get killed when it’s communication to server is closed. However a few may still be running.

Points Needed to be mentioned here:

  1. This tool works only when X11 server is running, as xkill is a part of X11 utility.
  2. Don’t confuse with Closing and killing a resource. While killing a resource you may expect it not to exit cleanly.
  3. This is not a replacement of kill utility.
Do I need to go to Linux command line to invoke xkill?

No, you don’t need to fire xkill from Linux Command Line. You may set a keyboard shortcut and call xkill just by punching same key combination.

Here is how to setup a keyboard shortcut on a typical gnome3 Desktop Environment.

Go to Settings –> Select Keyboard, click on ‘+’ and add name and command. Click on the new entry and press the key you want to use as shortcut key combination. I did Ctrl+Alt+Shift+x.

Gnome Settings
Gnome Settings
Add Shortcut Key
Add Shortcut Key

The next time you want to kill a X resource just call the key combination (Ctrl+Alt+Shift+x), and you will notice your mouse pointer changed into x. Click on x resource you want to kill and all done!

Avishek
A Passionate GNU/Linux Enthusiast and Software Developer with over a decade in the field of Linux and Open Source technologies.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.