When my computer freezes up, usually its really easy to resolve the problem by going into the terminal and running top to find out whats eating up the memory and killing that process. It can be difficult sometimes when its badly frozen up, I have to hit CTRL + ALT + F1 to get into the terminal. Also its handy to have a keyboard shortcut setup for running xkill so I can kill GUI apps that I know are freezing it up.

What I haven't figured out how to deal with, even after years of having this problem is these unresponsive browser scripts. Sometimes my computer freezes up so badly I can't move the mouse pointer, and eventually it unfreezes and I see that one of the browsers (used to always be firefox, lately its been chrome), there will be a popup saying that a javascript script is not responding. It gives me the option of killing it but hitting the kill button never seems to resolve the problem.

How do you deal with this problem? Also how do you deal with memory overload problems in general? I used to just hit CTRL + ALT + T, run top, and see what program was using the most memory then kill it, but thats a lot of steps and when your computer is frozen, a single step can take a long time. So I'm looking into better ways, like setting up a killswitch to do it in one step, or setting up a daemon that will kill any programs that are about to freeze up the machine.

Also whats the best way to find out which program is causing the problem? top isn't always easy to see because sometimes top shows no programs eating up excessive CPU, but if I scroll down I see there are about 50 instances of this program running, so it would be a whole lot better if I could see combined CPU usage of the program. Firefox and chrome are the two main culprits, occasionally sublime-text-3 (maybe this is due to having too many tabs open?).

So I found this command:

ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

Which gives this list right now:

  PID  PPID CMD                         %MEM %CPU
 6896   968 /opt/google/chrome/chrome - 13.1  2.7
27334  4769 /usr/lib/firefox/firefox     6.6 13.0
 5607  4769 /usr/bin/compiz              4.7 44.7
26381 26363 /usr/lib/libreoffice/progra  2.7  0.0
  953  4769 /opt/google/chrome/chrome h  2.0  3.0
 2777  2457 /usr/lib/xorg/Xorg -core :0  1.8 29.5
 6980  4769 /usr/lib/x86_64-linux-gnu/z  1.6  0.0
 8180  8167 mono /usr/lib/AirVPN/AirVPN  1.6  2.1
 1096   968 /opt/google/chrome/chrome -  1.4  0.1

My computer isn't frozen right now so its alright, but firefox itself is freezing up when I try to use it. I tend to keep loads of tabs open, is that why I see so many instances of chrome and firefox when I run top?

I see htop gives a lot more options than top, so its probably a better tool for diagnosing the issue. Theres a few things I don't understand about all this, firstly which is more important %CPU or %MEM when it comes to your computer freezing regularly. htop allows you to sort by either one, heres what it shows me when I sort by memory usage:enter image description here

and heres what I get when I sort by CPU usage:enter image description here

So like I saw from running ps, firefox and chrome are taking up most of the memory, and compiz is taking up most of the CPU. Are there any other important factors to look at when it comes to unfreezing your system? For example, does the length of time a process has been running for come into play, I see compiz has been running longer than anything else:enter image description here

As for a killswitch, I found one that someone else wrote:

while [ 1 ]; do 
    echo checking for run-away process ...

    CPU_USAGE=$(uptime | cut -d"," -f4 | cut -d":" -f2 | cut -d" " -f2 | sed -e "s/\.//g")
    PROCESS=$(ps aux r)
    TOPPROCESS=$(ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | grep -v PID | head -n 1)

    if [ $CPU_USAGE -gt $CPU_USAGE_THRESHOLD ]; then
        kill -9 $(ps -eo pid --sort=-%mem | grep -v PID | head -n 1)

        echo "High memory usage process killed $TOPPROCESS\n"
        echo "Load average was at $CPU_USAGE\n"
        echo 'CPU Load Back to Normal'
        exit 0

But I'm not 100% sure how it works or what it does. When I run:

uptime | cut -d"," -f4 | cut -d":" -f2 | cut -d" " -f2 | sed -e "s/\.//g"

Its returning numbers like 149, 179, 178. I read the uptime manual and can't understand how its useful for preventing your system from freezing up.

They're not process IDs I see in any of the top memory using apps shown by htop.

Running uptime by itself, I get this:

17:49:53 up 1 day, 11:09,  2 users,  load average: 3.16, 2.45, 2.03

So my system has been up for 17.49 hours. I don't know what the load average means in terms of my computer. I was given this computer by my brother recently since he had an unused one at his office, when I check the specs:

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 26
Model name:            Intel(R) Core(TM) i7 CPU         940  @ 2.93GHz
Stepping:              4
CPU MHz:               1867.000
CPU max MHz:           2934.0000
CPU min MHz:           1600.0000
BogoMIPS:              5852.21
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              8192K
NUMA node0 CPU(s):     0-7

I'm pretty shocked, its a beast, 8 CPUs. And the RAM:

free -lm
              total        used        free      shared  buff/cache   available
Mem:          12005        7154         311         531        4539        3996
Low:          12005       11694         311
High:             0           0           0
Swap:         30516        1002       29513

12 Gb, my God I had no idea. My old laptop had 2 Gb. So its a mystery why its freezing like this now.

So what I'm wondering is:

1.) Whats the best way to find out what is causing your system to slow down and freeze?

2.) How do you deal with this specific unresponsive script situation without having to kill the actual browser? I use plugins like NoScript, but often times I need to enable javascript. Also certain plugins use scripts too. Why does killing them never resolve anything, is it because they can't actually be killed like that? Would there be a way to write a script that will search through your browsers and find which tab is running the page with the unresponsive script, then close, and restart the tab? Or better yet, just kill the script itself in a way that enables computer to run properly again? I don't know why an unresponsive script freezes my whole system, I'm guessing the browser eats up excessive memory when its trying to run the crashed script.

2.) Whats the best way to unfreeze your system, especially in those worst case scenarios when you can't move the mouse pointer. Would a shortkey combo connected to a killswitch be the way to go?

3.) For making a kill switch, how would you go about doing it? What should the script do? Should it find out which program is using the most memory and/or CPU and kill it. I'd prefer to take a more sophisticated approach because in certain cases the app thats using most memory or CPU might be something I need to keep open, such as if I'm working on firefox and killing it could cause loss of data I'm writing. I can supply the script with a list of apps which are less important, so it can run through that list and evaluate if they are eating enough memory that makes it worth killing them.

4.) Would increasing the size of the SWAP partition help?


Your bottleneck is whatever appears maxed out in a task manager like htop. In this case, it appears to be RAM overflowing with Chrome tabs. Fortunately, Chrome comes with its own task manager that allows you to see and kill which tab is hogging your RAM:

Google Chrome Task Manager

Chrome extensions like The Great Suspender and Lazy Tabs also help save RAM.

If Chrome is not the culprit, and you need a responsive system fast, see: Hurry! Ubuntu is quickly running out of RAM, and my computer is headed for a complete freeze! What command will save me?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.