What to do when Ubuntu Freezes/Crashes?

All operating systems freeze sometimes, and Ubuntu is no exception. It so happens that when Ubuntu Freezes, all you’re left with is a blank screen or a non-working mouse/keyboard or perhaps you have a particular program that has crashed/frozen. What could you do to debug and regain control before you decide to pull the plug and restart all over? Does a magic combination like Ctrl + Alt + Delete exist for Ubtuntu? Lets find out…

1. If a single Program stops working

Usually a single unresponsive program can be terminated simply by clicking the X-shaped close button at the top left of the window which would generally result in a dialog box saying that the program is not responding (but you already knew that) and presenting you with the option to kill the program or to continue to wait for it to respond.

Sometimes this does not work as expected. In such cases, you can hit Alt+F2 (or the windows key) and run xkill. Your mouse cursor will turn into an X. Hover over the offending window and left-click to kill it. Right clicking will cancel and return your mouse to normal. Here is in-depth tutorial to see this is detail.

Kill a program from the terminal

  • You can usually halt a program running in the terminal with Ctrl+C.
  • To kill a program by its name, use killall xyz where “xyz” is the name of the program
  • If that doesn’t work, find the name and process ID of your program and kill the process. To get the Process ID (PID), you can use ps or top aux in the terminal or graphically by launching the System Monitor. Now kill the process using
    kill [process ID here]. It sends the default signal SIGTERM (15).
  • If all this fails, as a last resort, you can force-kill by sending SIGKILL (9) as follows:
    kill -9 [process ID here]

Note that force killing the process provides the kernel no opportunity to cleanup. The process just stops to exist. It always works provided you have the permission to kill. In some special cases the killed process maybe listed by ps or top as a zombie entry only because it’s needed later.

Kill all programs and re-login

Sometimes, you don’t know which program is causing a lag or a slowdown, in this case you can certainly restart your computer, but a better way is to simply kill all the processes and relogin. If your GUI is working, then you can simply logout and re-login, but if your desktop/navbar is also frozen, then launch your terminal and execute the following –

kill -9 -1

This kills all the processes and logs you out. You should then be able to re-login with your usual display manager.

2. When the mouse stops working

If the keyboard is still functional, press Alt+F2 and run gnome-terminal or try ctrl+alt+T (or, if these fail to launch, press Alt+Ctrl+F1  to switch to console and login with your username and password). From there you can troubleshoot things or kill offending processes as described in the previous step.

Restarting the GUI

You may want to try restarting the GUI.

// For Ubuntu 12.04 to 20.04 and above (lightdm is the default display manager)
sudo service lightdm restart

// For Ubuntu 11.04 or earlier (as gdm used to be the default display manager):
sudo service gdm restart

// For Kubuntu, (default display manager is kdm)
sudo service kdm restart

If you’re using another display manager, replace lightdm/gdm/kdm with its name.
Once you execute, it should bring down the GUI, which will then attempt to respawn, bringing you back to the login screen.

Ubuntu Freezes

3. Ubuntu freezes: When everything, keys, mouse,.. stop working

Try the Magic Combination as follows:
While holding Alt and the SysReq (Print Screen) keys, type REISUB.

  • R –  Switch to XLATE mode
  • E –  Send Terminate signal to all processes except for init
  • I –   Send Kill signal to all processes except for init
  • S –  Sync all mounted file-systems
  • U – Remount file-systems as read-only
  • B – Reboot

REISUB is BUSIER backwards, as in The System is busier than it should be, if you need to remember it. Or mnemonically – Reboot Even ISystem Utterly Broken.

There exists less radical way than rebooting the whole system. If SysReq key works, you can kill processes one-by-one using Alt+SysReq+F. Kernel will kill the most «expensive» process each time. If you want to kill all processes for one console, you can issue Alt+SysReq+K.

Note: You should explicitly enable these key combinations. Ubuntu ships with sysrq default setting 176 (128+32+16), which allows to run only SUB part of REISUB combination. You can change it to 1 or, that which is potentially less harmful, 244. To do this:

sudo nano /etc/sysctl.d/10-magic-sysrq.conf
// now switch 176 to 244

echo 244 | sudo tee /proc/sys/kernel/sysrq

It works immediately! You can test it by pressing Alt+SysReq+F.

Restarting the Machine

If you want to do a clean system reboot, execute the following from your terminal(ctrl+alt+T) or your console (ctrl+alt+F1) :

sudo shutdown -r now

Hardware Issues:

If you’re getting a lot of freezes, there might be something wrong with your hardware. Try Memtest86+ to check for fault due to low memory. If tests fail, try installing a RAM with greater capacity. Ubuntu doesn’t tend to leak memory over time. Even if one application or a poor video driver does, you can simply restart the GUI and just keep going on and on.

It might be useful to temporarily simplify your configuration to have just the graphics card connected with a standard keyboard and mouse. All other cards should be removed/disabled. For acpi related issues, try booting with noapic nomodeset in your grub boot option. Its also worth trying acpi=off although this could have other undesirable effects such as constant fan usage. Also worth checking the bios version level and seeing if the vendor has a newer bios version.

Lastly, you may wanna troubleshoot by uninstalling third party graphic drivers but before going ahead, don’t forget to backup your system with a good backup tool like CloneZilla.

Hope you may never reach this point! 😛


Leave a Reply