#Linux

Linux unfreeze guide

What should we do when our computer's GUI freezes in Linux?

· 5 min read
Linux unfreeze guide
Photo by Elisa Ventur / Unsplash

Let's face it, this isn't as obvious as Ctrl+Alt+Delete.

Have you been working on something very important, maybe it's a time critical commit that needs to be pushed ASAP while you are executing a CPU intensive task on the background and suddenly everything freezes and stops working?

Whatever the case it may be, we've all been there and it's not as obvious on how to release our machines from that perpetual state of unresponsiveness. This is a simple guide on how to unfreeze our Linux machines from that state.

Processes, Processes Everywhere!

The most common way of unfreezing your machine is by killing the process or parent process that is giving you trouble. Of course this will discard any unsaved data in that program and programs spawned by it.

I barely have control 😅

Assuming you have control on the machine. If you do, you could try the following:

  1. Ctrl+Alt+t to open up a new terminal emulator.
  2. On the terminal run ps aux to list all processes on the terminal.
  3. Pipe it into a grep command to "search" for the process name.

For example:

$ ps aux | grep chrom
hugomar+    7670  2.5  5.2 17385448 317052 ?     Sl   Mar11  35:18 /opt/google/chrome/chrome --enable-crashpad
hugomar+    7677  0.0  0.0 16798672 2604 ?       Sl   Mar11   0:00 /opt/google/chrome/chrome_crashpad_handler --monitor-self --monitor-self-annotation=ptype=crashpad-handler --database=/home/hugomarquez/.config/google-chrome/Crash Reports --url=https://clients2.google.com/cr/report --annotation=channel= --annotation=lsb-release=Debian GNU/Linux 11 (bullseye) --annotation=plat=Linux --annotation=prod=Chrome_Linux --annotation=ver=97.0.4692.99 --initial-client-fd=5 --shared-client-connection

Find the parent process and kill it!

$ kill 7670

Where 7670 is the process's ID, this will kill this process and all of its children, which will lead to closing the google chrome program on this example.

The Kill Command 💀

The kill command is used to send a signal to a process, the default signal for kill is TERM. If you need more information on this command and how to make a force kill, remember you always have man on your side.

ℹ️
Remember to read the system reference manual of kill
$ man kill

Some form of control 😥

If you move your cursor or pointer and it moves, you might still have some form of control over the machine, you could try to xkill the process that is giving you trouble. xkill is a command that kills a client process by its X resource and it is a utility for forcing the X server to close connections to a client.

To use this utility, try to open up a terminal emulator with Ctrl+Alt+t and type xkill, the mouse pointer will change to an icon of a skull and crossbones, and the next window you click will be killed. It is worth mentioning that in KDE you can run xkill with Ctrl+Alt+Esc by default. On GNOME you can create your own macro to run the xkill command.

XKill example

No control at all 😱

So you have tried Ctrl+Alt+t to open up a terminal emulator and... nothing happens. If this is your case, your Desktop Environment might be unresponsive as well, where your cursor doesn't move and your key presses seems to do nothing at all. You might be thinking "aagh maybe is time for a hard reset 🤢", but I'm here to tell you there might be another way.

TTY

TTY has a complex history going back to 1800's, but for our concerns it is worth to know that TTY stands for teletype and it is an abstract device in Linux. It might refer to a physical input device or to a virtual teletype where it allows users to interact with the system. We can see all the ttys in our system by cycling through tty1 to tty7, to do this we use the following commands Ctrl+Alt+F1 to Ctrl+Alt+F7.

If you do this you might have notice that tty1 is used to display logs and tty7 is used to run the desktop environment, that leaves us with tty2 to tty6 to try to find and kill the process that is giving you trouble. Try going to tty2, log in with your credentials and apply the ps and grep combo seen above.

The Last Resort 😭

If you have tried the above methods with no success, you might still have some sort of communication with the kernel. It might be time to use SysRq key in combination with the following to perform a reset:

  1. Press Ctrl+Alt+F2 to switch to tty2.
  2. Press Alt+SysRq+R to get the keyboard.
  3. If pressing Ctrl+Alt+F2 before failed, try it again now.
  4. Press Alt+SysRq+E to term all processes.
  5. Press Alt+SysRq+I to kill all processes.
  6. Press Alt+SysRq+S to sync your disks.
  7. Wait for OK or Done message.
  8. Press Alt+SysRq+U to umount all disk drives.
  9. Wait for OK or Done message.
  10. Press Alt+SysRq+B to reboot.

The letters REISUB is a mnemonic for Reboot Even If System Utterly Broken. To see the full list of available commands checkout the wikibook guide on linux freezes.

The Last Last Resort 🤮

⚠️
This can cause problems to your machine and the file system so be warned about the risks.

If everything else has failed, well it might be time to perform a hard reset, this means to press the physical power button on your machine in order to send the signal to the kernel to perform a reset. If this doesn't work you could try long pressing or cutting off electrical power to the machine.


Resources

This post is based on information retrieved by the following guides and blog posts, so if you want more information on this matter I recommend you check them out:

Linux Guide/Freezes - Wikibooks, open books for an open world
What is TTY in Linux? - It’s FOSS
You must have heard about the term “TTY” when it comes to Linux and UNIX. But, what is it actually? This article explains the essentials.
Teleprinter - Wikipedia