What should I do when Ubuntu freezes?

  • All operating systems freeze sometimes, and Ubuntu is no exception. What should I do to regain control when...

    • just one program stops responding?
    • nothing at all responds to mouse clicks or key presses?
    • the mouse stops moving entirely?
    • I have an Intel Bay Trail CPU?

    In what order should I try various solutions before deciding to pull the power plug?

    What should I do when starting up Ubuntu fails? Is there a diagnostic procedure I can follow?

    You should meditate and start learning Windows or MacOS! far more stable than linux.

    Those are 2 different issues - the freeze, and failure to boot.

  • koanhead

    koanhead Correct answer

    10 years ago

    When a single program stops working:

    When a program window stops responding, you can usually stop it by clicking the X-shaped close button at the top left of the window. That will 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. If you can't close a window by normal means, you can hit Alt+F2, type xkill, and press Enter. Your mouse cursor will then 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.

    If your program is running from a terminal, on the other hand, you can usually halt it with Ctrl+C. If not, find the name and process ID of its command, and tell the program to end as soon as possible with kill [process ID here]. It sends the default signal SIGTERM (15). If all else fails, as a last resort send SIGKILL (9): kill -9 [process ID here]. Note that you should only use SIGKILL as a last resort, because the process will be terminated immediately by the kernel with no opportunity for cleanup. It does not even get the signal - it just stops to exist.

    (Killing a process by kill -9 allways works if you have the permission to kill. In some special cases the process is still listed by ps or top (as "zombie") - in this case, the program was killed, but the process table entry is kept, becuse it's needed later.)

    When the mouse stops working:

    If the keyboard still works, press Alt+F2 and run gnome-terminal (or, if these fail to launch, press Alt+Ctrl+F1 and login with your username and password). From there you can troubleshoot things. I'm not going to get into mouse troubleshooting here, as I haven't researched it. If you just want to try restarting the GUI, run sudo service lightdm restart. This should bring down the GUI, which will then attempt to respawn, bringing you back to the login screen.

    When you have an Intel Bay Trail CPU

    See https://askubuntu.com/a/803649/225694.

    When everything, keys and mouse and all, stop working:

    First try the Magic SysReq method outlined in Phoenix' answer. If that doesn't work, press the Reset button on the computer case. If even that doesn't work, you'll just have to power-cycle the machine.
    May you never reach this point.

    I've recently discovered that, rather than the "ps $options | grep $process_name" referenced above, one can just enter "pgrep $process_name" to achieve approximately the same result (for certain values of $options).

    @Chan-Ho Suh Not being able to start up isn't really "freezing". We cover failure to boot in http://askubuntu.com/questions/162075/my-computer-boots-to-a-black-screen-what-options-do-i-have-to-fix-it. Or do you mean freezing on login?

    One should never recommend `kill -9` right off the bat. Once should instead attempt to kill the process with less drastic signals first, and only use -9 if all else fails.

    Why REISUB is useful when the system freezed? I can't find which option in REISUB can get control back to my own except reboot. Thank you~

    `sudo service lightdm restart`: Not awesome - will kill all gui processes in Ubuntu 13.04 at least - for me that included running Virtual Machines etc :(

    In case of temporary hangs when the storge media is being used constantly especially if it is slow (flash card / stick) you can try reducing the memory allocated to dirty bytes to about 4 MB. In /etc/sysctl.conf write vm_dirty_bytes = 4194304 and vm.dirty_background_bytes = 1048576 also reduce waiting time to 3 seconds vm.dirty_expire_centisecs = 300 and vm.dirty_writeback_centisecs = 300 (increasing the buffer makes the freezes longer and less frequent !)

    @sam the `S` and `U` in `REISUB` take care that the harddisk write operations get finished before reboot, to avoid inconsistent, half-written data. The harddisk writes could take very long in the case that the system is "almost hanging" in some lowlevel way.

    @ScottSeverance Very true - but the Answer says to first try `kill` without giving signal. That will use the default signal `SGTERM`, which is the right one to try before `SIGKILL`, I think.

    For a command not running in a terminal, no need to try `SIGHUP`, it's saying the connection dropped ("hangup"), like when you see `CARRIER LOST` on a dialin modem connection. (Some daemons reread configuration `SIGHUP`.) The default signal, `SIGTEM` is telling the program "terminate as soon as possible" - so it can do important cleanup before. `SIGKILL` does not tell the programm anything - it tells the kernel "delete that program" - so it just stops to exist. It will just never get a next CPU cycle. So it can not do any, because it never finds out that it will stop to exist. (I'll edit.)

    "May you never reach this point." In most Linuxes, this is the only point reached. I have never seen a Linux freeze that can be fixed.

    I must say this Alt+F2, type xkill was a crazy thing i didn't knew, totally saved the day

    Go out of your house and turn the power board switch off, works every time ;)

  • If it locks up completely, you can REISUB it, which is a safer alternative to just cold rebooting the computer.

    REISUB by:

    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
    

    Some mnemonics for REISUB:

    • Rise up (from the dead) if you're inclined to zombie movies
    • BUSIER backwards, as in The System is busier than it should be!
    • Reboot Even If System Utterly Broken.
    • Or the classic: Raising Elephants Is So Utterly Boring

    This is the SysReq key:

    SysReq key

    NOTE: 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 mostly «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 (all commands enabled) or 244 which is potentially less harmful. To do this:

    sudo nano /etc/sysctl.d/10-magic-sysrq.conf
    

    and switch 176 to 244; then

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

    It will immediately work! You can test this by pressing Alt+SysReq+F. For me, it killed active browser tab, then all extensions. And if you will continue, you can reach X Server restart.


    More info on all the Alt+SysReq functions here.

    In the event you're forced to do this, do it slowly. Let a few seconds pass in between each keypress so that the commands you're invoking have a chance to finish before you go to the next one.

    In case you like mnemonics: Raising Elephants Is So Utterly Boring, or Reboot Event If System Utterly Broken. I've also seen it as RSEIUB (Raising Skinny Elephants is Utterly Boring).

    I actually came up with this one and try to remember it this way: "Reset System Environment In UBuntu". or "Reset Environment In System UBuntu".

    What do you do if you're using a Mac that has no SysRq key?

    What if I have a keyboard without `SysRq`, and `Print Screen`? In my Italian keyboard there is none of those. I have `Stamp`, `Bloc Scorr`, `Pausa/Interr`.

    @Bakuriu it should be `Stamp`.

    Does this work only when it freezes?! I just tried to test if it works by pressing Alt+Fn+SysReq (Dell laptop keyboard) but did not work!

    Thankfully, Alt Gr works as well according to the Wikipedia article. Otherwise it would be quite an exercise to type while simultaneously pressing Alt (on the left side) and SysRq (on the right side). Btw from the wiki article again: "Under graphical environments (such as GNOME or KDE) 'Alt'+'PrintScrn/SysRq'+key combination generally only leads to a screenshot being dumped. To avoid this Print Screen feature the magic SysRq combination should include the Ctrl, becoming 'Ctrl'+'Alt'+'SysRq'+key."

    BTW, Magic-SysRq appears to not work out of the box at least in Kubuntu 14.04 LiveCD: I get "This sysrq operation is disabled" on any Magic-SysRq command. One has to enable it by `echo 1 > /proc/sys/kernel/sysrq`. But it does on the installed Kubuntu 14.04.

    @Ruslan I added some information on how to setup desired keys to be enabled.

    Is it recommended to restore from a backup after doing this?

    Does this rely on how the keyboard is connected to the box ? PS2 , USB, bluetooth, or 2.4G?

    I normally remember that it's BUSIER backwards but, I don't know what each letter does. What about: Raw Execution Insist Sync Umount Bang!

    Why the REI part is not enabled by default? I found that part more useful than the SUB part..

  • You can make the shortcut Ctrl+Alt+Delete open the System Monitor, with which you can kill any unresponsive applications.

    1. Open up System ➜ Preferences ➜ Keyboard Shortcuts and click Add.
      In the Command field, enter gnome-system-monitor. Name the shortcut whatever you want.

    enter image description here

    1. Click Apply and then click where it says Disabled. Now hit the keys Ctrl+Alt+Delete

    enter image description here

    1. Close Keyboard Shortcuts and try out the shortcut:

    enter image description here

    but if X is locking up fully, or even the kernel is hung, you can't do much with a keyboard shortcut.

    Unfortunately, System Monitor is quite CPU intensive. It typically consumes up to 20% of my CPU, so if you're computer's bogged down, launching SM is only going to grind it into the dirt faster.

    If you can open System Monitor you can get to a terminal, in which case your OS is not frozen.

    System Monitor is, unfortunately, not the trusty Task Manager on Windows. As commented above, it will only launch if (ironically) Ubuntu isn't frozen. And even if it does, it's unresponsive anyway.

  • Freezes such as you have described can be both software and hardware related and as you have found sometimes frustratingly difficult to diagnose.

    Hardware

    If this is a desktop PC look at your hardware-cards. For both laptops and desktops possibly acpi type issues.

    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.

    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. The readme notes should hopefully reveal if any newer version fixed crashes and freezes.

    Software

    I note you have tried the standard 270 drivers but have failed due to freezes. Can you clarify if you had similar issues with the open-source driver? Obviously you will not get Unity during testing this.

    Graphics freezing can be one of/or a combination of the driver/compiz/X/kernel

    If you are willing to try any of the suggestions below first backup your system with a good backup tool such as CloneZilla. You will need an external media device to receive the image such as a large USB stick/drive or separate internal hard-drive.

    Installing newer nVidia driver

    Deactivate (uninstall) your current 173-nvidia driver using the Additional Drivers window.

    There are a small number of important fixes primarily in the 275 stable but a small number also in the 280beta that fixed freezes - it is worth a shot to see if these apply to your graphics card. Unfortunately nvidia dont go into detail on which cards they specifically fix (readme.txt)

    However - I would strongly recommend a backup unless you feel confident on reversing a nvidia install - especially since you had serious issues with the slightly older 270 drivers. I've used clonezilla countless times and it has always got me out of trouble. You do need a large external drive though - USB stick/external drive or a separate drive.

    X Updates

    The latest graphics drivers have been packaged in the x updates ppa.

    Note - this will lead you away from the standard baseline - if upgrading in the future ppa-purge the PPA itself before upgrading.

    You can also manually install the drivers from nVidia:

    Try installing the latest nvidia stable 275 or 280 drivers - 32bit 280 drivers: ftp site and 64bit: 280 drivers: ftp site

    To Install

    CTRL + ALT + F1 to switch to TTY1 and login

    sudo service gdm stop
    

    To stop the X server

    sudo su
    

    To run as root

    cd ~/Downloads
    sh NVIDIA-Linux-x86-280.04.run
    

    To install the 32bit driver (equiv for 64bit) then reboot.

    To uninstall

    sudo sh NVIDIA* --uninstall
    

    Also remove /etc/X11/xorg.conf

    X/Kernel/Compiz

    If you run classic Ubuntu with effects do you get the same freeze issues as standard Ubuntu? If you cannot reproduce the freeze with classic Ubuntu (no effects) then this will point you towards a compiz issue. I would raise a launchpad bug report with the compiz team.

    If space is available (e.g. 20Gb), you could dual boot/install alongside the latest oneiric alpha. Obviously this will itself be unstable, but it will come with the latest X and Kernel. You may need to also install manually the beta 280 graphics drivers above since it probably will not be offered in the Additional Drivers window.

    If during testing you dont see the same freeze activity you could try uplifting your X version with the x-edgers ppa and using kernel kernel 3.0 in Natty. Going this route is not really desirable - and could cause you upgrade issues in the future - and may have other unforeseen stability issue. Again, use ppa-purge to remove the PPA.

    Kernel 3.0 is packaged with the PPA - you'll need to install the headers as well as the kernel itself from synaptic BEFORE rebooting if you intend to install the nvidia drive later.

    This is a testing ppa - do have a ready backup if you want to try this route.

    ... Are you sure this is a good idea, and that it might solve the problem? Or is this just a guess? As I had a lot of trouble with nvidia-current and nothing worked... That's why I switched to the nvidia-173 one. Can I simply restore my whole system from a CloneZilla back-up? The problem is that I haven't got a spare hard drive anymore to put a system copy on...

    I'll try... Though I haven't got a hard drive to make a back-up to, so I'll just hope it doesn't break my whole system. About feeling uncomfortable using beta software: I'm working on Ubuntu 11.10 Alpha 3 at the moment xD But for work I just use Ubuntu 11.04 as I don't need constant bugs and sometimes crashes while making a website or something similar :p

    Oh dear xD I installed the NVidia-275 driver, and rebooted. X didn't start anymore. No problem, after looking into the log files I saw that another driver was already using the device. I added nouveau to the modprobe blacklist, rebooted, and X started again... But now I've got another problem... I get to see the Unity interface, and then everything simply freezes :p I can switch to the tty's and run commands and everything, but it just seems Unity and the window manager/decorator have crashed. I can't switch back to Gnome Panel (and honestly, I wouldn't want to), ...

    ... as I killed it a few weeks ago (on purpose, as it ran together with the Unity Panel for some strange reason :p). And don't tell me to go using Unity 2D please cause it doesn't work too well and easy for me. In fact, Unity is the only reason I still install non-open source drivers. So please help me? xD

    ... I already did that, except for re-enabling nouveau as I don't see the use of that. But I meant help me out with the freezing problem please.

  • If you're getting a lot of freezes, there might be something wrong with your hardware. I used to get hard lockups every 48 hours due to some less than optimal RAM. Memtest86+ showed the fault after 40 minutes of testing. Swapped the RAM out for some more (under warranty) and I'm now at 32 days, 1 hour of uptime.

    Ubuntu doesn't tend to leak its guts all over your memory like Windows can over time. Even if one application or a poor X video driver does, you can restart LigthtDM very simply and just keep going and going and going. I've actually been through three beta versions of the nvidia driver in this one boot :)

    Anyway... While knowing how to restart softly is a very handy thing, finding, reporting and fixing the system should be your next priority. If it's an always-on system, you should easily be able to make it between kernel updates* without needing a restart.

    *You should restart when you get kernel updates as they'll be security fixes that won't be applied until you reboot into the newer kernel.

    I agree that RAM is usually the culprit for unstable systems. I had a problem once that Memtest86+ was not able to found but I could trigger it repeatedly in 5 minutes running sha1sums on very big files repeatedly (checksums changed every now and then). It, too, was fixed by changing memory sticks. Other common causes are unstable power source or poor capasitors on the motherboard. The only way to diagnose these issues is to keep swapping parts until it works.

    +1 for memtest86. RAM can be faulty without you really noticing it in daily use.

  • When everything stops working, first try Ctrl + Alt + F1 to go to a terminal, where you can likely kill X or other problem processes.

    If even that doesn't work, try using holding down Alt + SysReq while pressing (slowly, with a few seconds between each) R E I S U B.

    This puts the keyboard in raw mode, ends tasks in various states, syncs the disks, etc, and finally reboots the machine. You will get much better results doing this than just pulling the plug. Of course, if this fails, you're pretty much left with pulling the plug.

    A way to remember "REISUB" is "Reboot Even If System Utterly Broken".

    or "Raising Elephants Is So Utterly Boring" :P

    I remember it using "BUSIER" Backwards

    Between `Ctrl`+`Alt`+`F1` and trying to kill processes, and `Alt`+`SysRq`+`R` `E` `I` `S` `U` `B`, it's worth pressying `Ctrl`+`Alt`+`Delete`. If you successfully got to a text-based virtual console (from having pressed `Ctrl`+`Alt`+`F1`), this will virtually always reboot the machine.

    Much blunter and in Spanish: REInicia SUBnormal

  • Also, sometimes it's simply the X-Server which hangs - a case I've most often found when you're using Compiz.

    If this is the case you can kill X, which will restart and drop you back at the log-in screen.

    The default sequence is Ctrl + Alt + Backspace

    Although this is turned off by default (presumably new-users were accidentally hitting it) and can be turned back on like this:

    1. SystemKeyboard (i.e. the Keyboard Preferences Dialogue)
    2. Layouts tab
    3. Click the Options button
    4. At the Key Sequence to kill the X server point check Ctrl + Alt + Backspace.

    If your video driver is using kernel modesetting (KMS), it's unlikely this will be sufficient to fix lockups, you have to use sysrq or power cycle. (Go ahead and try C-A-B, it obviously can't hurt; it does work when an app (like compiz/unity) is stuck, rather than X itself, however other answers on this page would be better in this case). But when it doesn't work, now you know why. :-)

    A note for new users about KMS: As a general rule, if you're using a binary driver (probably if you have an nVidia graphics card, and sometimes if you've got an ATI card) you're video driver is not using KMS.

    I can't find this in Ubuntu 14.04. When I go to Settings > Keyboard the tabs are only Typing and Shortcuts. I just looked through all the shortcuts and couldn't find "Key sequence to kill the X server". Can I still do this on 14.04?

  • My first favourite when total freeze occured - Alt + SysRq + K.

    That combo kills X, and returns me to the graphical login screen. If that doesn't work, try Alt + SysRq + R E I S U B.

  • In such cases you can try CTRL-ALT-F1 to get to a console. Then login with your password.

    Restarting the GUI

    You can try to restart your graphical desktop with:

    sudo service lightdm restart
    

    If you're running Ubuntu 11.04 or earlier, you should use this instead (as gdm used to be the default display manager):

    sudo service gdm restart
    

    If you're using Kubuntu instead, then the default display manager is kdm, so you should instead use:

    sudo service kdm restart
    

    If you're using another display manager, replace ligthdm/gdm/kdm with its name.

    Restarting the Machine

    If you want to do a clean system reboot, use:

    sudo shutdown -r now
    
  • DoR and Phoenix has answered this well. To make this page more complete I would add:

    If it is only X that is "broken", than you can use kernel to kill it:

    SysRq + Alt + K

    For laptops (depends on the model, typically needed if "SysRq" is written in blue):

    Fn + SysRq + Alt + K (release Fn after pressing SysRq).

    FWIW it depends on the laptop -- on my ThinkPad Alt+SysRq doesn't require Fn nor Ctrl.

    The key pressing sequence is neatly described here (Ubuntu Forums: http://ubuntuforums.org/showthread.php?p=11773367#post11773367), particulary for laptop where 'Fn' key makes a difference. I had to follow it on my Lenovo Ideapad - hold 'Fn' with left hand first, press Alt + SysRq in right, leave 'Fn' and continue with REISUB slowly.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM