xkill

systemLinux/Unix
The xkill command is one of the most frequently used commands in Linux/Unix-like operating systems. xkill Force close unresponsive X clients by killing their associated windows

Quick Reference

Command Name:

xkill

Category:

system

Platform:

Linux/Unix

Basic Usage:

xkill [options] [arguments]

Common Use Cases

    Syntax

    xkill [-button number] [-frame] [-id resource] [-all] [-display displayname]

    Options

    Option Description
    -button number Specifies the mouse button to use to select the window (default is 1, the left button)
    -frame If specified, xkill will kill the window that contains the pointer, not just the window directly under the pointer
    -id resource Specifies the X resource ID of the window to be killed
    -all Kills all windows on the screen
    -display displayname Specifies the X display to use (default is from the DISPLAY environment variable)

    Mouse Buttons

    For the -button option, common values are:

    Value Button
    1 Left button
    2 Middle button
    3 Right button

    Examples

    How to Use These Examples

    The examples below show common ways to use the xkill command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    Start xkill and select a window to close
    xkill
    Use the right mouse button instead of the left to select the window
    xkill -button 3

    Advanced Examples:

    Force close a window by its resource ID (obtained from xwininfo)
    xkill -id 0x1200001
    Close all windows
    xkill -all
    Include window frame when closing a window
    xkill -frame
    Specify a display
    xkill -display :0.1

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `xkill` command is a simple but effective utility for forcibly closing unresponsive X Window System applications. It's often used as a last resort when an application freezes and won't respond to normal close commands. **How xkill Works:** 1. **Direct Window Killing**: xkill sends a X protocol `KillClient` request to the X server for the selected window's client. This bypasses the normal application shutdown process. 2. **Window Selection**: When run without parameters, xkill changes your cursor to an 'X' or a skull-and-crossbones (depending on your X configuration), and waits for you to click on a window. The clicked window's client application is then terminated. 3. **Signal Mechanism**: Under the hood, xkill typically results in a SIGKILL signal being sent to the application process, which cannot be caught or ignored by the application. **Use Cases:** 1. **Frozen Applications**: The primary use case for xkill is closing graphical applications that have frozen and won't respond to normal close methods (like clicking the window's close button or using Alt+F4). 2. **Applications Without Close Options**: Some poorly designed X applications might not provide a clear way to exit. xkill provides a universal way to close any X window. 3. **Batch Window Management**: With the `-all` option or by specifying window IDs, xkill can be used in scripts to close multiple windows programmatically. **Advantages and Limitations:** **Advantages:** 1. **Simplicity**: xkill is straightforward to use - just run it and click the problematic window. 2. **Effectiveness**: It can close windows that are completely unresponsive to other methods. 3. **Universality**: Works with any X window, regardless of the application or window manager. **Limitations:** 1. **Forceful Termination**: Since xkill forcibly terminates applications, any unsaved work in the application will be lost. 2. **No Cleanup**: Applications closed with xkill don't get a chance to clean up temporary files or save state. 3. **Potential Side Effects**: Killing an application abruptly can sometimes leave orphaned processes or locked resources. **Best Practices:** 1. **Last Resort**: Use xkill only after trying normal methods to close an application (e.g., application menus, Alt+F4, window manager controls). 2. **Target Carefully**: Be careful which window you click with xkill, especially when using desktop environments where clicking the desktop or panel might kill essential components. 3. **Consider Alternatives**: For less drastic measures, consider: - Using `pkill` or `kill` commands if you know the process name or ID - Restarting the X session (typically with Ctrl+Alt+Backspace if enabled) - Using application-specific methods to force quit (e.g., GNOME System Monitor) **Comparison to Similar Tools:** 1. **kill and pkill**: Command-line utilities that send signals to processes by PID or name, requiring you to know the process information. 2. **Desktop Environment Tools**: Most desktop environments provide a graphical task manager (e.g., GNOME System Monitor, KDE System Guard) that allows selecting and ending processes. 3. **xdotool**: A more versatile X automation tool that can manipulate windows in various ways, including closing them normally (sending close events rather than killing). **Technical Details:** 1. **X Protocol**: xkill uses the X11 protocol's `KillClient` request, which is sent to the X server. 2. **Resource IDs**: When using the `-id` option, the resource ID is a hexadecimal identifier for a window in the X server. These can be obtained using tools like `xwininfo`. 3. **Display Selection**: The `-display` option allows targeting windows on a specific X display, useful in multi-monitor setups or when using X forwarding. **Historical Context:** xkill has been part of the X Window System's utility collection since the early days of X11. It represents one of the fundamental characteristics of the X architecture - the ability to manage windows and clients through a standardized protocol, even when the applications themselves are not responding. While modern desktop environments have added more sophisticated application management tools, xkill remains valuable as a simple, universal method to deal with unresponsive X applications.

    Related Commands

    These commands are frequently used alongside xkill or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the xkill command works in different scenarios.

    $ xkill
    View All Commands