Take the 2-minute tour ×

I want to close all windows appearing on my desktop. I've thought to do this through pkill, but I could only manage to kill them one at a time, which is not what I want. The end goal is to put this into a script to run a kiosk, it will detect if the kiosk software is running (I figured this part out) and if it is not, then it will kill any windows that are open, and restart my kiosk software.

share|improve this question
how about restarting gdm or kdm –  Raza Jul 21 at 18:09

3 Answers 3

The simplest approach uses xdotool:

xdotool search "" windowkill %@

xdotool search "" lists every window. windowkill %@ kills every one of them; %@ refers to all the results of the previous search.

You may prefer to use the --maxdepth 1 option to search to limit the windows selected to top-level windows.

share|improve this answer

Michael Homer and Guido van Steen have shown ways to kill all windows. This wouldn't kill background processes, if there are any. It wouldn't kill crashed programs whose window has gone but that are still executing without a user interface. So you may prefer to kill the processes instead.

You can run kill -9 -1 as a non-root user to kill all the processes that are running as that user. You would need to run the kiosk application as a dedicated user (that's a standard configuration for kiosks anyway, for security) and to ensure that the kiosk interface restarts when all processes in the session are dead (which is also a standard configuration for kiosks, for robustness).

share|improve this answer

this works at least for kde and xfce (gnome not tested, but it might work as well):

1) install wmctrl

2) then create a script called close_windows.sh:

# close all open windows gracefully without closing the Desktop environment
WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' ')
for i in $WIN_IDs; do wmctrl -ic "$i"; done
# Keep checking and waiting until all windows are closed (you probably don't need this section)
while test $WIN_IDs; do 
    sleep 0.1; 

3) make it executable:chmod +x ./close_windows.sh

3) create an entry in the start menu that points to the close_windows script.

4) execute the close_windows script from this entry.

source: https://forum.manjaro.org/index.php?topic=4412.0:

share|improve this answer

Your Answer


