184

I'm a Windows guy, dual booted recently, and now I'm using Linux Mint 12

When a Windows desktop freezes I refresh, or if I am using a program I use alt + F4 to exit the program or I can use ctrl + alt + delete and this command will allow me to fix the Windows desktop by seeing what program is not responding and so on.

Mint freezes fewer times than my XP, but when it does, I don't know what to do, I just shut down the pc and restart it.

So is there a command to fix Linux when it freezes?

Lynob
  • 4,204

10 Answers10

149

If all else fails, you Raise The Elephant.  There are Magic SysRq key sequences (Alt+SysRq+?) that the Linux kernel handles specially.

If your Linux box freezes and simply won't yield to any other key-commands, you should definitely try one particular key sequence before a hard reboot.

The key sequence is popularly remembered with the mnemonic:

Raising Elephants Is So Utterly Boring

  • Alt+SysRq+R switch keyboard to 'raw' mode
  • Alt+SysRq+E send SIGTERM (termination) signal to all processes except mother init
  • Alt+SysRq+I send SIGKILL signal to all processes, a little more aggressive
  • Alt+SysRq+S sync all filesystems to prevent data loss
  • Alt+SysRq+U remount filesystems as read-only
  • Alt+SysRq+B forcefully reboot

For the full list of possible commands and additional tips on how to type these commands, see the Wikipedia page.

kwarrick
  • 3,128
  • 1
  • 16
  • 10
  • 13
    This does, of course, require that Magic SysRq support is compiled in. – Alexios Mar 14 '12 at 13:58
  • Do these also work as single independent commands? Like the R one followed by the E or I to just kill all and not restart? – arsaKasra Jan 13 '14 at 20:28
  • 1
    Yes, they should work as independent commands. Check the wikipedia page for more details. – kwarrick Jan 14 '14 at 20:32
  • 8
    Problem: some modern keyboards do not have a SysRq key... (the one I'm typing from right now doesn't, for instance - although it does have "print screen", "scroll lock" and "pause/break") – Dalker Feb 26 '14 at 10:28
  • 22
    @Dalker I just had success with using the Print Screen key instead of SysRq – flaviut Sep 23 '14 at 03:05
  • 10
    How much time should be allowed for between running each of these commands? – Highly Irregular Nov 18 '14 at 21:19
  • 49
    Reboot Even If System Utterly Broken – angrydust Feb 28 '16 at 21:49
  • 2
    Or just Alt+SysRq+U followed by Alt+SysRq+B. I don't know why so many websites push for this 6-command sequence; the first 3 don't do anything useful since you're going to reboot anyway, and U does sync by itself so the S is redundant. – Gilles 'SO- stop being evil' Apr 08 '17 at 23:25
  • I've pressed Alt+SysRq+B but it didn't work? should I press all the keys in the sequence? should I enable any options? I'm running Ubuntu 16.04, thanks for the help – user10089632 Feb 06 '18 at 14:14
  • 1
    @HighlyIrregular Wait for several seconds between U and B, or until you observe that disk activity has fully stopped, otherwise you are cutting off the filesystem at a delicate moment in the middle of a dismount. – Boann Jan 29 '20 at 20:25
  • 1
    @user10089632 Its probably because the keys are disabled. Most distributions currently disable access to some SysRq functions by default due to security reasons. To know whether its enabled do: cat /proc/sys/kernel/sysrq. A value of 0 means all are disabled and 1 means all are enabled and anything else means some are enabled. This should enable all SysRq functions: echo "1" | sudo tee /proc/sys/kernel/sysrq – rashid Oct 28 '20 at 05:36
136

You can try Ctrl+Alt+* to kill the front process (Screen locking programs on Xorg 1.11) or Ctrl+Alt+F1 to open a terminal, launch a command like ps, top, or htop to see running processes, and then launch kill on non-responding process.

Note: if not installed, install htop with sudo apt-get install htop.

Also, once done in your Ctrl+Alt+F1 virtual console, return to the desktop with Ctrl+Alt+F7.

Mathieu
  • 2,719
  • 7
    For a windows guy and a beginner in Linux, I would recommend installing htop instead of top as it is easier to operate. – Palec Sep 02 '14 at 14:01
  • 2
    Wasn't the kill foreground process under pointer key combination Ctrl + Alt + Esc, or did that change? (And why do my key buttons not show correct formatting?) – Franki Nov 27 '14 at 05:44
  • 4
    Which asterisk should in use for Ctrl+Alt+*? The one on the numeric keypad or in the alpha block? In the latter case, what would I press on non-US keyboards? – user149408 Jan 29 '15 at 10:11
  • See the Command Line answer here too (http://askubuntu.com/a/19873/327339). Use k to kill a selected process, followed by default option 15 to kill it nicely, or 9 to kill it right away. – Gabriel Staples Nov 07 '16 at 20:30
  • 1
    Only the asterisk on numeric keypad should work, @user149408. The linked thread in oss-sec mailing list suggest that. – Palec Jan 30 '17 at 16:04
  • On Mint I have to press crtl+alt+f8 to return back to the gui – charsi Jun 14 '17 at 17:25
  • I don't seen anyone mentioning this but what you can also do is restart the lightdm service. So switch to virtual console CTRL+ALT+F1 and type "sudo service lightdm stop" and then "sudo service lightdm restart". This will essentially log you out and then you can log back in. – revolutionary Dec 01 '17 at 14:55
  • 1
    My console opens with Ctrl+Alt+F3 not F1 . I'm using fedora workstation 28 – Accountant م Jul 05 '18 at 20:41
  • 1
    None of those worked for me. I can only use the server via SSH. The local console is absolutely unresponsive (mouse, keyboard and monitor all frozen). – Paulo Carvalho Jan 25 '19 at 10:30
  • In Fedora, the key is any of Ctrl+Alt+F[3-6]. – rashid Oct 27 '20 at 18:01
44

In most distros pressing Ctrl+Alt+Backspace kills the X11 (graphic) interface and restarts it. Unfortunately some recent, supposedly "user friendly" distros deactivated this very useful shortcut for some unfathomable reason. I don't know if Mint is so "user friendly" but you have nothing to lose trying it :)

wazoox
  • 1,364
  • 6
    Make sure this is enabled in Mint by searching for 'Startup Applications' in the menu, and then making sure 'Ctrl Alt Backspace' is checked. – Jeshurun Apr 12 '13 at 10:58
  • 1
    AFAIRK,the newer fancy xorg evdev input drivers disable the 'zapping' by default. However, there is a way to reenable them on startup in /etc/xorg.conf or /etc/xorg.conf.d/XX-somefile or set it in a per-user xorg startup script (maybe put setxkbmap -option "terminate:ctrl_alt_bksp" into ~/.xinitrc) by adding the line Option "XKbOptions" "terminate:ctrl_alt_bksp" into a corresponding Section "InputClass", or by setting another switch in your OS that relays to do that. – Franki Nov 27 '14 at 05:57
  • This is ON for my system, but the Ctrl/Alt-Backspace was no help. However, when I used: Ctrl/Alt-F1 to login to the console and ran htop -- I was able to observer the handbrake processes hard-at-it! After I saw that the one remaining process was idle -- Ctrl/Alt-F8 brought me back to Cinnamon desktop. I think handbrake is just hungry ... – will Mar 17 '16 at 12:31
  • 1
    It is still on by default in OpenSUSE Tumbleweed. – Geoffrey Dec 03 '16 at 10:52
  • 1
    In Fedora [install,] open gnome-tweaks and check 'key sequence to kill Xserver' in the mouse/keyboard section – d.k Jul 15 '19 at 14:35
  • 1
    Run dpkg-reconfigure keyboard-configuration to enable it (in the last step) in Ubuntu. – Zheng Qu Jul 22 '21 at 08:48
13

Besides what was already mentioned, I also use these tricks:

  • If by any chance the unresponsive program was started in a terminal, I try Ctrl+D or Ctrl+C. If nothing happens I try Ctrl+Z followed by a ruthless kill.

  • If I know the responsible program, I open a terminal and use killall (e.g. killall firefox).

  • Alternatively, under Gnome, I launch run command and invoke xkill, which allows you to kill a program by simply clicking on a window it owns.

  • Finally, just in case my keyboard melts, I have a System Monitor applet (also under Gnome) which will pop up the gnome-system-monitor when clicked. From there, I can kill any process I own using only my mouse.

11

Adding one more possible solution to the mix, and (apart from the accepted answer) one of the least destructive of the answers so far.

If you cannot:

  • Use keyboard/mouse to A) Run the Ctrl+Alt+* option above, B) Navigate to a utility that can be used to terminate the offending program, C) Launch a terminal to initiate a pkill <process name> (or similar, as detailed above)

-OR-

  • Switch to another virtual console (Ctrl+Alt+any one ofF1-6), to initiate a pkill <process name> (or similar, as detailed above)

... then assuming MagicSysRq support is compiled into the kernel (From http://en.wikipedia.org/wiki/Magic_keys), on a QWERTY keyboard (alternatives for the below f are provided in the aforementioned article), one can try:

Alt+SysRq(Note caveats on http://en.wikipedia.org/wiki/Magic_keys#Commands)+f to
"Call oom_kill, which kills a process to alleviate an O ut  O f  M emory condition", which (at least for me) often kills the program that is causing the issue, as it is the largest RAM consuming process running at the time.

user66001
  • 2,395
10

On laptops you might need to press CtrlFnF1 to open terminal, what I do is type reboot now to restart from terminal.

To go back to the GUI from terminal on my laptop (HP G56) I have to CtrlFnF8 (apparently it could also be CtrlFnF7) and you should be back to graphical interface.

Also check http://community.linuxmint.com/tutorial/view/244

Stopping & Starting

  • shutdown -h now – Shutdown the system now and do not reboot
  • halt – Stop all processes - same as above
  • shutdown -r 5 – Shutdown the system in 5 minutes and reboot
  • shutdown -r now – Shutdown the system now and reboot
  • reboot – Stop all processes and then reboot - same as above
  • startx – Start the X system
jasonwryan
  • 73,126
Seb
  • 101
7

Another suggestion if you are using Gnome3 (I think the default Mint installation uses something similar), you can use CTRL+F2 then press R and hit return. I use this often and it works. It basically restarts the GUI. Even if you don't see anything on the screen (e.g., it is frozen) you should do that and it will restart the GUI.

bahamat
  • 39,666
  • 4
  • 75
  • 104
Hanan
  • 5,771
  • ctrl f2 does not work anymore :( dunno why – Lynob Feb 16 '12 at 20:10
  • maybe isn't works in the Mint GUI, since the default Mint GUI isn't exactly Gnome, but on Gnome 3 it works for sure. – Hanan Feb 16 '12 at 20:51
  • 3
    Instead of Ctrl+F2, press Alt+F2. Then it works fine. –  Mar 09 '12 at 16:43
  • 1
    This changed in GNOME3. Pressing Alt+F2 will open a run box where you can type the command r. This is restarting gnome-shell, which in GNOME 3.x has had many memory leaks which lead to it becoming slower and slower over time. Performing this restart released much of this RAM. – slm Mar 08 '14 at 06:39
3

On my laptop when it completely freezes (unresponsive mouse or keyboard) on mint 17.3, I'm able to do control + alt + fn + f7, then control + alt + fn+ f2. This gets to the shell, then I login with my username and password. To go back to the desktop I do chvt 8 this gets me back to my current desktop. To find out the active tty's type w then chvt to the current one.

That way you can resume your work without rebooting or losing anything.

answerSeeker
  • 2,417
3

Not yet mentioned but might work in some cases - try CTRL+ALT+RIGHTARROW or LEFTARROW. This did switch workspaces, and doing so somehow unhitched whatever was blocking mouse and keyboard actions. I could then switch back to the first workspace, kill Chromium, which I had by then figured had crashed and was hogging all keyboard and mouse events. Now everything's back to normal, no reboot or loss of anything involved.

In my case, just minutes ago, everything was hung except the mouse moved the cursor, but the mouse did no more. The PrtScn made a popup saying I could drag a rectangle (but not) or hit ESC (works). Nothing else worked. Not even moving the cursor onto another window, when I have focus-follows-mouse, changes the window frame highlighting. But Ctrl+Alt+F3 did switch to a text term, Ctrl+Alt+F1 brought back the X windows session.

The culprit was Chromium. I was reading, switched tabs in one browser window, and upon clicking the tab everything froze but for the few things just described. Switching workspaces

DarenW
  • 3,443
1

Alt+PrtSc or SysRz + r Really (return my keyboard to me)

Ctrl+Alt+F1 Wait. Go get some coffee, or make tea, or let the dog out. Sometimes with high CPU use it can take a while for this to work. If you get a console, then ps fu -e --sort -%cpu | head -n5 to track down the villian.

Alt+PrtSc or SysRz + j Just (unfreeze it)

Alt+PrtSc or SysRz + f F'ing (call the OOM)

Alt+PrtSc or SysRz + x fiX (it: Will kill the foreground including XWindows)

This should get you back to a terminal login. Login and figure out if anything is wedged. Then either reboot, or often you can just CtrlAlt⟵Backspace to restart XWindows (? Wayland).

DrKC
  • 23