What To Do When Linux GUI Freezes

What To Do When Linux GUI Freezes

Once in a while, your operating system might hang or freeze when you run too many resource-intensive applications.

Of course, you might not even be running any heavy software at times, but because two apps are struggling to access a single system resource, you might fall into a deadlock.

Unfortunately, Linux systems are also not spared in GUI (Graphical User Interface) hanging/ freezing.

So when we talk about GUI freezing, we mainly focus on these points:

  1. A single program stops responding (say browser) , and you can’t close the window: For this, you might likely see a notification “browser is not responding.”
  2. The entire GUI freezes, and the system doesn’t respond to mouse or keyboard events: You can easily notice this if you had some music playing in the background and it suddenly stops.
  3. The background processes are still running (e.g., music is still playing), but the system isn’t responding to mouse clicks, and the cursor is not even moving.

Besides running heavy software and deadlocks, a freezing GUI on Linux can also be caused by driver issues, misconfigured hardware, excess heating up, insufficient memory (RAM), BIOS settings (say overclocking), power issues, external devices, or even a faulty Hard drive.

Additionally, outdated packages can also result in a system freeze. Always ensure your system is up to date by executing the commands below:

sudo apt update
sudo apt upgrade

What to do when Linux GUI freezes?

Before cutting the power source or force-shutting your Linux system, below are some methods you can try to recover your frozen GUI and avoid losing unsaved work.

Method 1: Launch the X-Kill Command and Kill Frozen Apps

If you are experiencing a situation where only one application is freezing, and the system still responds to mouse clicks, this is one of the best methods to kill/stop it. There are two ways which you can use to run the X-Kill command.

The first is by pressing the keyboard combination Alt + F2. You will see a window pop-up, and you can enter the command you want to run.

Type the command xkill and hit Enter.

Run xkill
Press Alt+F2 and then run xkill

You will see the cursor change to an X sign. Just hover the cursor over the freezing application and click. The app will close instantly or after a few seconds.

run_xkill_cursor_change
After running xkill, the cursor changes to an X sign

Another way of launching running the xkill command is through the Terminal. Therefore, if you still have access to your terminal, execute the command xkill.

You will see the cursor change to an X sign, and you can click on any application to close it.

run_xkill_from_terminal

Method 2: Kill Processes From the Terminal

Another method you can use to come out of a frozen GUI is using the Terminal. In this method, you must have the terminal running or be able to launch it and send keyboard events.

If a freezing process was running on the Terminal, simply use the keyboard combination Ctrl + C to terminate it.

Ctrl + C

If a program wasn’t running from the Terminal, we could still kill it by getting its PID from the Terminal. Some of the tools we can use are TOP (comes pre-installed) and HTOP. If you don’t have htop installed, use top. Launch the Terminal (Ctrl + Alt + T), type top, and hit Enter.

top

You will see a real-time view of all the processes currently running on your system.

Top VLC
Real-time view of processes after running top in the terminal

From the image above, we can see all the running programs. We want to kill the VLC process, which has a PID of 44320.

We can easily do so by executing the command below:

sudo kill -9 44320

The application will terminate immediately.

Method 3: Switch to Console (Virtual Terminal) and Kill Freezing Apps

This method uses one simple logic – “If your GUI is freezing – switch to Console mode, there is No GUI there”. Once you are in the console (also called Virtual Terminal) mode, you can easily kill the freezing apps or any resource-intensive application you suspect might be causing the freezing.

To switch to console mode, just use the keyboard combination (Ctrl + Alt + F3). After a few seconds or immediately, you will see your GUI disappear, and you will drop to the console, as shown in the image below.

You will be required to log in. If you had some music playing in the background, it will not play while in console mode.

word image 4

Once you are in the console mode, you can use a TOP or HTOP to view all running processes and get their PIDs. We will use HTOP since I already have it installed. Unlike TOP, HTOP comes with additional features like:

  • Makes use of different colors to distinguish priority levels between process
  • Allows users to select a process by simply clicking on it
  • Scroll through (Up and Down) to view the running process
  • Search, Kill, Sort process using the Function keys
htop

Once you have selected the freezing program, press F9 to kill it.

Htop VLC

You can switch back to GUI mode using the keyboard combination (Ctrl + Alt + F2).

Method 4: Login Remotely via SSH and Kill Freezing Apps

That is another reliable method but requires you to have the SSH service running on your system. It is similar to Method 3 and Method 4, only that in this scenario, we will be doing it from a remote machine connected to the same network as your freezing PC. Linux users can use the Terminal, while Windows users will need to download a tool like Putty.

In this post, we will access our Freezing PC from another Linux pc. Below is the SSH command that I will use to create a session. I will be required to enter my user password.

ssh_freezing_apps

Once you have a running SSH session, you can run commands like TOP to see the running processes on your freezing system. From there, you can get the PID of your target process and kill it.

word image 7

From the image, we will kill the process – skypeforlinux with the PID 2374. I will execute the command below:

sudo kill -9 2374

Method 5: Use the Magic SysRq Key Sequences

If all the above methods fail – Its time to “Raise The Elephant!” Linux systems support a special Magic SysRq keyboard sequence that enables you to send low-level commands to the Linux Kernel. I call this the ultimate method as it’s meant to help in such situations.

Note: Nowadays, most keyboards don’t come with a SysRq key. However, you can find it on the Prnt-Scrn or Home button, but that might differ from one PC brand to another.

word image

The Magic SysRq keyboard sequence is popularly remembered with the mnemonic: Raising Elephants Is So Utterly Boring or Reboot Even If System Utterly Broken (R-E-I-S-U-B).

  • Alt + SysRq + R: Switch the keyboard to Raw mode.
  • Alt + SysRq + E: Terminate all processes except the mother init by sending a SIGTERM signal.
  • Alt + SysRq + I: Kill all processes with the SIGKILL command.
  • Alt + SysRq + S: To prevent data loss, use this sequence to sync filesystems.
  • Alt + SysRq + U: Unmount and mount the filesystems as read-only.
  • Alt + SysRq + B: Forcefully Reboot the system.

When executed in the right order (REISUB), this method works like a charm. Unless the hardware is completely locked and the kernel is utterly borked. Other than the REISUB sequence, you can check out other SysRq combinations in the Linux SysRq guide.

Conclusion

I believe you have learned five methods you can use to save your Freezing GUI from this post. If freezing GUI is a problem you face from time to time on your Linux PC, I think you should take a deeper look at the cause. Is it insufficient RAM (memory)? Is your system running on outdated packages?

You can decide to switch to a more lightweight distribution or Desktop Environment like XFCE. Sometimes, you also need to take a good look at the software you are running.

For example, when using Visual Studio Code for my React JS project, my GUI freezes since VS-Code always syncs my node modules folder. Excluding node-modules folders in the sync settings solved this issue.

Feel free to share with our readers other methods you can use to recover from a frozen GUI.

0 Shares:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
You May Also Like