Is there any software that will monitor applications that are rapidly starting to consume a lot of RAM and kill them? I’m confronted with the fact that when listening to music on VC, or when opening websites, the OS hangs tight (Opera browser), if you do not turn off the tab in time, but it is not easy to notice this. Memtest did not drive the RAM yet, because if I will buy new trims, then in a couple of weeks. And this problem gives a lot of inconvenience.

By the way, the vm.swappiness parameter is zero. Now put 10, maybe the problem will disappear

  • one
    google: // setting up oom killer linux, however, the memory has nothing to do with it, you either have a driver or a browser (or a bunch of browser + ubunt) are buggy. - strangeqargo
  • Such a problem was on windows, but the OS did not hang, allowing me to kill the process. The browser would not want to change, now I will google oom killer, thanks! - jessez
  • 3
    @jessez, write :) For ps -auxf | sort -nr -k 3 | head -10 : ps -auxf | sort -nr -k 3 | head -10 ps -auxf | sort -nr -k 3 | head -10 ps -auxf | sort -nr -k 3 | head -10 are the 10 processes that eat the most memory at the moment. Set the maximum value, if it is exceeded - kill. The script is written on the knee faster than the comment :) Another question is how justified it will be ... - PinkTux
  • one
    Well, this is already creative :) Now I'll try to pick something up for an example. - PinkTux
  • one
    The system hangs tightly if something is not eating at all a memory, but a time of the processor. - Sergey

1 answer 1

Here, for example, the dumbest approach. We will not go into details: how correct it is, whether we will bring down the system, etc.

 #!/bin/sh while [ 1 ] do # получаем %памяти, имя процесса, его PID и юзера: ps axo %mem,comm,pid,euser | \ # если процесс занимает больше 10% - убиваем: awk -F' ' '{ \ if( $1 > 10 ) { \ printf( "KILL %s:%s - %s\n",$2,$4,$3 ); \ system( "kill -9 " $3 ); \ } \ }' sleep 10 done 

You can go further: first determine how much memory is free, and start killing only if there is less than some limit left. Enter a list of unkillable exceptions, calculate not %% in general, but from occupied / free memory, etc. For example:

 #!/usr/bin/perl use Modern::Perl; # свободной памяти больше - не дёргаемся: use constant MIN_FREE_MEM => 40; # сколько %% памяти разрешается занимать процессу: use constant MAX_PROCESS_MEM => 10; use constant SLEEP_DELAY => 10; # будем использовать смотреть точное совпадение, # но можно и под регекспы переделать my %excludes = ( 'init' => 1, 'eclipse' => 1, ); while (1) { # элементы массива будут такими: # 0 1 2 3 # [ %памяти, имя процесса, его PID, юзер ] my @pinfo = map { s/^\s+|\s+$//g; [ split /\s+/ ]; } split "\n", `ps axo %mem,comm,pid,euser`; # удалить первую строку с заголовком shift @pinfo; my $free = 100.0; $free -= $_->[0] for @pinfo; # теперь мы знаем сколько %% памяти свободно if ( $free < MIN_FREE_MEM ) { # пропускаем исключения: next if $excludes{ $_->[1] }; for (@pinfo) { if ( $_->[0] > MAX_PROCESS_MEM ) { say "Killing process $_->[2]:$_->[1]:$_->[3] ($_->[0]%)"; kill '-KILL', $_->[2]; } } } sleep SLEEP_DELAY; } 
  • Here is a return :)) Thank you! And how to make a list with not killed exceptions? Intellij idea is eating a lot of memory, but I wouldn't want to kill it)) - jessez
  • Added exceptions. But I don’t know what the idea looks like, I suspect that there will hang processes with the simple name 'java' ... (I checked, exactly, two java processes, how the FIG know them only if all of the java are exceptions ). If you want to watch not the memory, but the processor load, then you can watch not the ps output, but top -b -n 1 , for example. However, the top and memory can be used. - PinkTux
  • thank! All java add exceptions :) The processor does not load at all when such a problem occurs. Thank you again! - jessez
  • oops, throws the error Scalar found where the operator expected at ./defenderOOM.sh line 40, near "'-KILL' $ _" (Missing operator before $ _?) syntax error at ./defenderOOM.sh line 40, near "'- KILL '$ _ " - jessez
  • one
    uh ... next if defined $excludes{$_->[1]}; - PinkTux