As you already know, Chrome and Firefox are memory eaters and thieves lol; Vscode doesn't help either and as if that weren't enough it creates a process with the TabNine extension that sometimes gets out of control exceeding 700Mb and even 1Gb.
Well, given the problem, I bring you the solution, to help others since I did not find it on the internet.
A Script to monitor an application and kill the process that consumes the most memory. The good thing is that it does not kill the entire application, only the process that exceeds the limit that you place on it:
first kill_mem.sh script
#!/bin/sh
numPro=$(ps aux | awk '{print $6,$2,$11}' | sort -nr|grep $1|head -1|awk '{print $2}')
while [ numPro=1 ];
do
numPro=$(ps aux | awk '{print $6,$2,$11}' | sort -nr|grep $1|head -1|awk '{print $2}')
SIZE=$(ps aux | awk '{print $2,$11,$6}' | sort -nr|grep $numPro|head -1|awk '{print $3/1024 " MB\t\t"}')
SIZEMB=${SIZE%.*}
echo "Process id ="$numPro" Size = "$SIZEMB" MB"
if [ $SIZEMB -gt $2 ];
then
echo "Tamaño se ha excedido.\nKilling the process......"
`kill -9 $numPro`
echo "Killed the process"
sleep 10
else
sleep 1
echo "Tamaño no se ha excedido"
fi
sleep 9
done
second script to place it in startup applications:
#!/bin/sh
cd ~/bin/scripts/
sh kill_mem.sh chrome 640 & sh kill_mem.sh TabNine 640
Well, you know how it is, paste it in a .sh file (recommended is in ~/bin/ if it doesn't exist, create the bin folder in your /home/youruser/bin) and give it execution permissions. The memory caps are in Mb, I recommend that you set a cap somewhat higher than what you want, for example my cap is 500Mb I put 640 because the output of the ps command shows a slightly higher consumption than the monitor of the system. But you are free to try and adjust it to your liking and need.
The script is designed to act as a police daemon in your system, that is, it will always be running and verifying, so I recommend that you comment the lines where text is printed with a #, you already know this way:
#echo "Killed the process"
: to avoid any consumption in the ram.
Well friends that's all, whoever wants to improve it is free and please share to help others who also need it.
Linux friends:
As you already know, Chrome and Firefox are memory eaters and thieves lol; Vscode doesn't help either and as if that weren't enough it creates a process with the TabNine extension that sometimes gets out of control exceeding 700Mb and even 1Gb.
Well, given the problem, I bring you the solution, to help others since I did not find it on the internet.
A Script to monitor an application and kill the process that consumes the most memory. The good thing is that it does not kill the entire application, only the process that exceeds the limit that you place on it:
first kill_mem.sh script
second script to place it in startup applications:
Well, you know how it is, paste it in a .sh file (recommended is in ~/bin/ if it doesn't exist, create the bin folder in your /home/youruser/bin) and give it execution permissions. The memory caps are in Mb, I recommend that you set a cap somewhat higher than what you want, for example my cap is 500Mb I put 640 because the output of the ps command shows a slightly higher consumption than the monitor of the system. But you are free to try and adjust it to your liking and need.
The script is designed to act as a police daemon in your system, that is, it will always be running and verifying, so I recommend that you comment the lines where text is printed with a #, you already know this way:
: to avoid any consumption in the ram.
Well friends that's all, whoever wants to improve it is free and please share to help others who also need it.
God bless you.