This might not happen often nowadays but sometimes the desktop gets frozen and you have no idea how to unfreeze it. It is especially frustrating when you have unsaved work and you see no other option than to restart losing on things you were working on.
Depending on what software runs with Linux there are different things you can do.
What about Windows?
Of course there is the task manager where you can dive in. When a program does something weird, just kill it. I usually right-click on the taskbar and select „Task Manager“. If that does not work just press CTRL+ALT+DEL and select „Task Manager“ from there. If that does not work anymore, so to say you have no access to these options, you might have to restart the system. I don’t know about any other method on Windows. Maybe you have an idea.
Now let’s get to Linux, there you can do a lot more.
First of all, if your system suffers often under such problems and you bother with it, you might want to try a different Distro or maybe even another operating system. Remember, there exist more stable distros and more experimentational ones. Of course Linux is not for everyone and not the only option.
Also software developers should be accustomed to the fact that operating systems might eventually break, because some performed operations yet to become stable in the being developed code have still a way there. If you have unprotected access somewhere to the hardware because you require it to be so, you should not be surprised if the operating system doesn’t take it that nicely.
Knowing different methods
I consider it useful to have a mix of different methods you can try out for some more confident usage. The goal of this article is to show what different things you can do under Linux when your system does not react anymore.
Know your Desktop Environment
Personally I like to have a quick access to something like a Process Manager, where I am able to kill processes that might become problematic.
If you use Ubuntu, Linux Mint or something with the Gnome Desktop it is called gnome-system-monitor what gives the control over the processes being executed. I also recommend having a watch over the system resources always visible so you can react fast enough by opening the system monitor and killing the process whenever required. Under Gnome I use this extension:
By opening the menu and just clicking on System Monitor… I get it opened. Also this extension has a lot of customization options, highly recommended.
For KDE Plasma there exist similar tools and the KSystemGuard does a good job there. You can also use it on Gnome but it is not recommended. It really belongs to KDE Plasma.
No reaction if I click on something
That situation might many people lead to give up, but there is a lot more you can try out. If only Gnome shell is frozen maybe other programs still run fine. There is a keystroke, try ALT+F2 and put the letter ‚r‘ into the box displayed. This restarts the gnome shell entirely, but the running programs remain open. It brings the system back into a more stable state.
Nothing in the Desktop Environment works anymore
If you cannot click on elements and the keystroke with ALT+F2 leads to no reaction, then you might need to get deeper. Linux is not all about desktop environments. The programs might be running in the background and if only a small component is hindering the process we only might have to kill it and go back.
Try to change the TTY (Terminal TYpe). That means, change to a console where you can type commands. Don’t worry, there not much typing to be done. On most systems you have the graphical interface (X or maybe Wayland) opened which is where you are now, mostly TTY2 (or TTY7 on older systems). Let’s change to TTY3 with CTRL+ALT+F3. You might be greeted with Login. Type in your username and password so you get a prompt.
If you have not done already, install htop. Under Ubuntu-like Systems (also Mint) you do this with
sudo apt install htop
Let it install if not done already and start that process manager with just typing
and you will see something like a console based windows which can be controlled using the arrows keys and the functional keys (F1-F10) for commands. Above the list you see how much load you have on your cores and how much memory is used in total.
With F9 you can kill the currently selected process. The processes at top of the list are those which take most of the CPU. You can sort the list differently or even show process trees. High CPU is a good indication where to look at, if your system behaves funny. Selecting the suspicious process (yes, it can even be Firefox if you have a cryptomining site with strange JS code running) and pressing F9 will open a list of signal to send. If you want to kill the process radically, you can choose 9 – SIGKILL and the kernel will kick this process out of the ecosystem.
Now if you see that the CPU or memory consumption lowered and you think it might have been the process making the desktop get frozen, you might want to switch back to the graphical interface. You can do that by just pressing CTRL+ALT+F2 (or CTRL+ALT+F7 on older systems).
If you were right the Desktop might be responsive again. If that did not help you can go back pressing (CTRL+ALT+F3) and will see that the htop instance still running and usable. Just continue looking what it could be and kill more problematic processes.
If everything is back to normal, you should consider that the TTY3 is a second session you opened. By quitting htop (Pressing F10) and typing exit as command the console session gets closed. I like to forget that session afterwards and when the PC is being shutdown later on you might get a message asking you if the other session should be closed also. Nothing to worry about.
No Reaction even after Switching TTY
I have no idea what to do then. Sometimes SSH can help if the kernel is active using another computer in the same network but if you are not even able to login, that might not work. In such cases you might have to really reboot the machine even cold hearted turning it off.
I do not remember having such situation under Linux but I know it can happen. I had kernel panics with hardware which was defective but only when booting. Still though such freezes can happen when the system is already running and at bad state somehow.
Here is a nice discussion and more hints by other developers:
If I debug into certain breakpoints in some application code which uses Qt libraries using the QtCreator as debugger frontend, I sometimes manage to freeze my desktop. But everything else really is running. The problem is mostly that sometimes Qt lib tries to pull all my events, so I cannot do a thing anymore using the Desktop Environment. This a situation where changing the TTY and killing the GDB instace stabilizes the Desktop back again. QtCreator gets a bit weird, but after some seconds it finds out GDB was killed and everything is fine again. You can continue working normally… 🙂
There is no perfect system but it is incredible what CPU power houses we have today. I hope these small hints help you having your system under control even in those infamous situations.